/*! * jQuery Tiny Pub/Sub - v0.X - 11/18/2010 * http://benalman.com/ * * Original Copyright (c) 2010 "Cowboy" Ben Alman * Dual licensed under the MIT and GPL licenses. * http://benalman.com/about/license/ * * Made awesome by Rick Waldron * */
/*! * jQuery Tiny Pub/Sub - v0.X - 11/18/2010 * http://benalman.com/ * * Original Copyright (c) 2010 "Cowboy" Ben Alman * Dual licensed under the MIT and GPL licenses. * http://benalman.com/about/license/ * * Made awesome by Rick Waldron * */
Writing Idiomatic JavaScript
1. Two space soft indents (fake tabs) OR tabs... BUT NEVER BOTH - DO NOT MIX 2. Whitespace, Parens, Braces, Linebreaks if/else/for/while/try always have spaces, braces and multiple lines. -------------------------------------------------------------------- // Bad
# Tips for jQuery Bug Patching # There are some assumptions made here, one being that you're # set up with some form of "localhost" http server and that it's running. # - http://www.mamp.info/en/mamp/ # - sudo apt-get install apache2 # Get it running: # On Mac: $ python -m SimpleHTTPServer
/* * Viewport - jQuery selectors for finding elements in viewport * * Copyright (c) 2008-2009 Mika Tuupola * * Licensed under the MIT license: * http://www.opensource.org/licenses/mit-license.php * * Project home: * http://www.appelsiini.net/projects/viewport * */
<!DOCTYPE HTML> <html> <head> <script src="sharedworker.multi-connect.renderer.js"></script> </head> <body> <pre id="shared-worker-log"></pre> </body> </html>
console.log(blanky); // `object definition` console.log(typeof blanky); // object console.log(blanky.__proto__); // object console.log(typeof blanky.__proto__); // object console.log(blanky.constructor); // SafetyBlanket() console.log(typeof blanky.constructor); // function console.log(blanky.constructor.prototype); // object{} console.log(typeof blanky.constructor.prototype); // object
<!DOCTYPE HTML> <html> <head> <script src="sharedworker.multi-connect.renderer.js"></script> </head> <body> <pre id="shared-worker-log"></pre> <pre id="shared-worker-connection-log"></pre> </body> </html>
Working through the indexedDB API that was released in Chromium 8.0.552.5 dev
<!doctype html> <html> <head> <title>IDB* API</title> <script src="idb.js"></script> </head> <body> <input type="button" id="button" value="message" /> </body> </html>
var supportedMimeTypes = ['video/mp4', 'video/x-ms-wmv']; var supportedVideoExtensions = ['.mp4', '.wmv', '.mp4v', '.m4v']; var getSupportedMediaSource = function(videoElement) { // If the video element source is supported, then we replace the tag. if (videoElement.src && isWMPSupported(videoElement)) { return videoElement.src; }
<?php header("Content-Type: text/event-stream\n\n"); echo 'data: ' . json_encode( array( 0 => array( 'time' => time(), 'message' => 'Some kind of foo' ), 1 => array( 'time' => time(), 'message' => 'Some kind of quux'
Array + concat + every + filter + forEach + indexOf + join + lastIndexOf + length + map + pop + push
// Declare an object literal as a namespace var Utils = {}; // Define an sort of ES5 forEach (this is demo only, so it's fast and loose) Utils.forEach = function(arr, callback) { var iter = 0, len = arr.length; for ( ; iter < len; iter++ ) {
Various pre-Harmony bits and pieces
<script type="application/javascript;version=1.8"> var toString = Object.prototype.toString; console.log( [ i for each ( i in [ 1,2,3,4,5 ] ) ] ); function $r( floor, ceil ) {
H264 Support Revision
<!DOCTYPE html> <html> <head> <title>H264</title> <script src="h264.js"></script> </head> <body> <video id='video' style="display:" controls>
Exercise to understand Lisp cons/car/cdr, by implementing in JS
<script src="cons.js"></script>
/* * def.js: Simple Ruby-style inheritance for JavaScript * * Copyright (c) 2010 Tobias Schneider * This script is freely distributable under the terms of the MIT license. */ (function(global) { __super__ = function(){ var caller = __super__.caller; if(caller !== caller._super){ return caller._super.apply(caller, arguments); } }
(function($){ var toString = Object.prototype.toString; var class2type = { "[object Boolean]": "boolean", "[object Number]": "number", "[object String]": "string", "[object Function]": "function", "[object Array]": "array", "[object Date]": "date",
Test: var foo = { bar : 'barberic' , baz : 'bazterd' , duck : 'punch' }; JSLint Results: Error: Problem at line 1 character 19: Bad line breaking before ','.
The example given on Ajaxian: // See comments below. // standard style var a = "ape", b = "bat", c = "cat", d = "dog", e = "elf", f = "fly",
(function (undefined) { function detectMutation() { mutationSupported = true; this.removeEventListener('DOMAttrModified', detectMutation, false); } var forEach = [].forEach, regex = /^data-(.+)/, el = document.createElement('div'), mutationSupported = false, match ;
(function ($) { $.fn.pollute = function (pollution) { // first we extend the pollution object to the window, nice! $.extend(window, pollution); // make sure we're really nasty, and pollute all the elements as well. return this.each(function () { for ( var junk in pollution ) { if ( typeof pollution[junk] === 'object' ) { $(this).pollute(pollution[junk]);
(function ($) { $.fn.pollute = function (pollution) { pollutants = { air:"SMOAK", water:"OIL", noise:"BLAH" } window.emit = function(type) { var i = Math.round(Math.random()*1000); while(--i) {
<!DOCTYPE html> <html> <head> <title>Workers: Basic Demo</title> <script> document.addEventListener('DOMContentLoaded', function () { var worker = new Worker('worker-javascript-file.js'); worker.postMessage('Hello Worker!');
<!DOCTYPE html> <html> <head> <title>Workers: Compatibility</title> <script> // This script is executed in the main window /* we'll use a worker to filter a huge data set for all entries that match our filter string "foo" */
<!DOCTYPE html> <html> <head> <title>$.detonate()</title> <script src="http://code.jquery.com/jquery.js"></script> <script src="jquery.detonate.js"></script> <script> $(function () { $.charge( '/fuse',
importScripts('jquery.hive.pollen.js'); $(function (data) { // message received from rendering process $.ajax.get({ url: 'proxy.php', data: $.param(data), dataType: 'json', success: function(jsonObj) { $.each(jsonObj.results, function (i, result) {
/* jQuery.Mines.Charge/Detonate/Disarm() */ ;(function($){ var _payloadCache = {}; function blast(fuses, args) { $.each(_payloadCache[fuses], function(){ this.apply($, args || []); }); }
<!DOCTYPE html> <html> <head> <title>Shared Workers</title> <script> var worker = new SharedWorker('sharedworker.js'); console.log(worker); worker.port.addEventListener('message', function(event) {
<!DOCTYPE html> <html> <head> <title>Um. Duh?</title> <script src="http://github.com/DmitryBaranovskiy/raphael/raw/master/raphael-min.js"></script> <script> // WORKS FINE. console.log(Raphael); </script> </head>
(function($canvas) { var // STORE DEFAULT CELL ATTRS cellAttrs = { fill: "#E0E4CD", stroke: "#000", "stroke-width": 2 }, // SET UP CELL ARRAY $cells = [], // DRAW INITIAL CELL $cell = $canvas.circle( /* coordX, coordY, radius */
/* Usages: $(selector).classList() //returns an array of classnames $(selector).classList('newclass') //replaces the current element's classes $(selector).classList(['new', 'class', 'names']) //replaces the current element's classes */ jQuery.fn.extend({ classList: function( value ) { if( value ){ if( jQuery.isArray(value)){ this.attr('class', '')
<!DOCTYPE html> <html> <head> <title>jquery.classes.js</title> <script src="jquery-1.4.2.js"></script> <script src="jquery.classes.js"></script> </head> <body> <p class="foo bar baz">classes: foo, bar, baz</p> <p class="foo">classes: foo</p>
import urllib import optparse import os.path import pickle def truncate(message,limit): if len(message) > limit: # break off at 137 chars and concat elipsis return message[:(limit-3)] + "..." else: # not too long
.mouse{ position: absolute; background-image: url('../images/cursor.png'); width: 15px; height: 22px; z-index: 100; }
Burst({ 'arbitrary-timeline-name' : { start: 0, frames: 100, ratio: 1, loop: false, finish: function () {}, tracks: { 'arbitrary-red-square' : { ref: redBox.style,
<!DOCTYPE html> <html> <head> <title>Badges</title> </head> <body> <script src="badge.js?type=jedi"></script> <script src="badge.js?type=ninja"></script> <script>
$.mines.detonate('/fuse/c', ['message']); $.mines.detonate([ { key: '/fuse/a', args: ['message from fuse a', { foo: 'bar' }] }, { key: '/fuse/b', args: ['message from fuse b', ['an', 'array'] ] },
$(function () { var Pict = { api: { url:'http://ajax.googleapis.com/ajax/services/search/images' }, atCache: 0, cache: [], clear: function ( fn ) { this.cache.length = 0; if ( fn && $.isFunction(fn) ) { fn(); }
<!DOCTYPE html> <html> <head> <title>Dead Simple Twitter Search API jQuery Feed</title> <script src="http://code.jquery.com/jquery.js"></script> <script src="jQuery.twitterFeed.js"></script> <script src="jquery.twitter-usage-ex.js"></script> <link href="jQuery.twitterFeed.css" media="screen" rel="stylesheet" type="text/css"> </head> <body> <h1>Twitter:</h1> <div class="twitter-posts"><h3>Loading Tweets From The Cloud With AJAX HTML5...</h3><hr class="space"/></div>
$LAB.script("http://code.jquery.com/jquery.js").wait(function () { var tally = 0; jQuery(function () { function loopClickEmToRunEm() { setTimeout(function () { jQuery('#button_1').trigger('click'); }, 0); setTimeout(function () { jQuery('#button_2').trigger('click'); }, 3000); setTimeout(function () {
/* The constructor It takes the worker file name as an argument */ var worker = new Worker('worker-javascript-file.js') /* The postMessage() function sends a message to the worker
<?php header("Content-Type: text/event-stream\n\n"); echo 'data: ' . json_encode( array( 'from' => 'event-source' ) ) . "\n"; ?>
// close stream: label-a $.eventsource('close', 'label-a'); // close stream: label-b $.eventsource('close', 'label-b'); // close all open streams $.eventsource('close');
// Results at 10,000,000 iterations // $([]) omitted/not tested - caused chrome to crash // $('null') omitted/not tested - caused chrome to crash $(""): 1274ms $(""): 1270ms $(""): 1278ms $(""): 1265ms $(undefined): 1199ms $(undefined): 1167ms
<!DOCTYPE html> <html> <head> <title>jQuery hide/show speed</title> <script src="http://code.jquery.com/jquery.js"></script> <script> $(function () { var iter = 100000, $p = $("p");
// FROM: // http://www.quora.com/Is-there-a-way-for-jQuery-to-return-a-single-object-instead-of-an-array-of-objects-For-example-if-I-use-an-id-selector#ans94625 // This is actually a good thing var foo = $("#foo") // but it's important to indicate that // this var is a collection, and should // be declared as: // // var $foo = $('#foo')
(function(){try{if(!google.doodle)google.doodle={};var a=200,g=-200,j=-200,k,l,m,n=0,o=0,p=0,q=35,r,s=[],t,u,v;google.doodle.init=function(){if(!v&&window.location.href.indexOf("#")==-1){v=true;if(t=document.getElementById("hplogo")){google.j&&google.j.en&&w(100,x,function(){return google.rein&&google.dstr});w(100,y,function(){return google.listen});w(100,z,function(){return google.browser})}}};var w=function(b,c,d){if(d())c();else b< 200&&window.setTimeout(function(){w(b+1,c,d)},b)},x=function(){if(!google.doodle.n){google.doodle.n= true;google.rein.push(google.doodle.init);google.dstr.push(A)}},y=function(){google.listen(document,"mousemove",B)},B=function(b){a=200;g=b.clientX-t.offsetLeft;j=b.clientY-t.offsetTop},C=function(){return[u?window.screenLeft:window.screenX,u?window.screenTop:window.screenY,document.body.clientWidth]},z=function(){u=google.browser.engine.IE&&google.browser.engine.version!="9.0";s=[D(202,78,9,"ed9d33"),D(348,83,9,"d44d61"),D(256,69,9,"4f7af2"),D(214,59,9,"e
<!DOCTYPE html> <html> <head> <script src="foo.js"> { "foo" : "bar" } </script> </head> <body> </body> </html>
// 1: how could you rewrite the following to make it shorter? if (foo) { bar.doSomething(el); } else { bar.doSomethingElse(el); } // 2: what is the faulty logic in the following code? var foo = 'hello';
// 1: how could you rewrite the following to make it shorter? if (foo) { bar.doSomething(el); } else { bar.doSomethingElse(el); } // Rick says: There is more then one way to optimize this foo ? bar.doSomething(el) : bar.doSomethingElse(el); // Peter Higgins' solution was neat.
// Given var a = true, b='b', c='c'; (a?b:c) // via @cowboy [c,b][1-!a] // via @rwaldron
/*! * postMessage detector - v0.1pre - 9/15/2010 * http://benalman.com/ * * Copyright (c) 2010 "Cowboy" Ben Alman * Dual licensed under the MIT and GPL licenses. * http://benalman.com/about/license/ */ // If `window.postMessage.complex` is true, postMessage can pass complex non-string // values like objects and arrays. If it's false, it can only pass strings (TODO: test) //
var X = function () { return new X.prototype.init() ; }; X.prototype = { init: function () { this.y = 0; return this; }, y: 1 };
<html> <head> <script> var worker = new Worker('worker.js'); worker.addEventListener('message', function (event) { console.log(event.data); }); </script>
$(document) .ajaxSend(function (event, xhr, aOpts) { $('<div/>', { id: 'loading-indicator', text: 'Working...', css: { position: 'fixed', top: '0', left: '0' } }).prependTo('body');
/* ------------------------------ Main Class ------------------------------ */ // Returns "instances" of itself which are actually functions. function Ben ( greeting ) { var Parent, scope function Scope () { // Here is where you put your normal constructor junk this.greeting = greeting this.colours = [ 'yellow', 0xFFFFFF ] } // Magic function Proxy() { Scope.prototype.init.apply( scope, arguments )
/** * This library defines magic properties and methods * for objects. Generic hooks are: __get__, __set__, * __delete__, __count__ and __noSuchProperty__. * * Used features: Harmony (ES6) proxies. * * Tested in FF4 beta. * * @author Dmitry A. Soshnikov <dmitry.soshnikov@gmail.com> * (C) 2010 Mit Style License */
<!DOCTYPE html> <html> <head> <title>List navigation</title> <style> .selected { background: yellow; } </style> <script src="http://code.jquery.com/jquery.js"></script> <script src="linav.js"></script>
<!doctype html> <html> <head> <script src="http://code.jquery.com/jquery.js"></script> <script src="script.js"></script> </head> <body> <textarea id="whatever">foo bar #hash</textarea> Proof Of Concept: If you arrow right until just before the #hash and type shift-@, a "faked" autocomplete will trigger and insert @user - but will retain the string following. Currently, if you try this in #newTwitter, it will blow away any text following the autocompleted @user.
Per wycats suggestion to overwrite function.prototype.call
var originalCall = (function () { return Function.prototype.call; })(); Function.prototype.call = function () { console.log(arguments); return originalCall; } function testFn(arg) {
/*! * jQuery log selector - v0.1pre - 10/22/2010 * http://benalman.com/ * * Copyright (c) 2010 "Cowboy" Ben Alman * Dual licensed under the MIT and GPL licenses. * http://benalman.com/about/license/ */ // Log the selector used to select elements to each selected element, // otherwise to the body. Hover over logged selectors to highlight // stuff all fancy-like (note: don't select SPAN elements because this
overwrites function.prototype.call with enforced scope. (the closure seems unnec. but is, when running in FF)
var originalCall = (function () { return Function.prototype.call; })(); Function.prototype.call = function () { console.log('Logging:', arguments); return originalCall; }
<?php echo "Prepping CSS and JS for deploy...\n"; $css_files['app'] = array('reset', '960', 'screen', 'jquery.tagsinput', 'jquery.autocomplete', 'tipsy', 'prettify'); //$css_files['splash'] = array('reset', 'splash'); //$css_files['iphone'] = array('reset', 'screen', 'iphone'); $js_files['app'] = array('jquery.autocomplete.min', 'jquery.tagsinput', 'jquery.scrollTo-1.4.2-min', 'forrst', 'jquery.tipsy', 'jquery.autoresize.min', 'prettify', 'lang-apollo', 'lang-css',
jsfiddle html panel contents
#foo { height:100px; width:100px; padding:20px; border:1px solid; }
will build a special version of jquery that allows for iframe context's to inherit jquery from window.top
V ?= 0 SRC_DIR = src TEST_DIR = test BUILD_DIR = build PREFIX = . DIST_DIR = ${PREFIX}/dist RHINO ?= java -jar ${BUILD_DIR}/js.jar CLOSURE_COMPILER = ${BUILD_DIR}/google-compiler-20100917.jar
var states = ["Alabama", "Alaska", "Arizona", "Arkansas", "California", "Colorado", "Connecticut", "Delaware", "Florida", "Georgia", "Hawaii", "Idaho", "Illinois", "Indiana", "Iowa", "Kansas", "Kentucky", "Louisiana", "Maine", "Maryland", "Massachusetts", "Michigan", "Minnesota", "Mississippi", "Missouri", "Montana", "Nebraska", "Nevada", "New Hampshire", "New Jersey", "New Mexico", "New York", "North Dakota", "North Carolina", "Ohio", "Oklahoma", "Oregon", "Pennsylvania", "Rhode Island", "South Carolina", "South Dakota", "Tennessee", "Texas", "Utah", "Vermont", "Virginia", "Washington", "West Virginia", "Wisconsin", "Wyoming", "Alabama", "Alaska", "Arizona", "Arkansas", "California", "Colorado", "Connecticut", "Delaware", "Florida", "Georgia", "Hawaii", "Idaho", "Illinois", "Indiana", "Iowa", "Kansas", "Kentucky", "Louisiana", "Maine", "Maryland", "Massachusetts", "Michigan", "Minnesota", "Mississippi", "Missouri", "Montana", "Nebraska", "Nevada", "New Hampshire", "New Jersey", "New M
// SMELLY: HTML in your JavaScript $('#showMessage').click(function() { $('<div>' + '<h1>' + $('#messageTitle').val() + '</h1>' + '<p>' + $('#messageText').val() + '</p>' + '</div>') .appendTo('#messageContainer') }); // MINTY FRESH: Use templates instead <script type="text/x-jquery-tmpl" id="messageTemplate"> <div>
<!doctype html> <html> <head> <meta charset="utf-8"> <title>Detect Credit Card Type</title> </head> <body> <form> <label for="card_number">Enter Card Number:</label>
<!doctype html> <html> <head> <meta charset="utf-8"> <title>Detect Credit Card Type</title> </head> <body> <form> <label for="card_number">Enter Card Number:</label>
An example from the JSDoc #usage page.
// Usage example revised /** * Shape is an abstract base class. It is defined simply * to have something to inherit from for geometric * subclasses * @constructor */ function Shape( color ) { this.color = color; }
/*! * jQuery htmlDoc "fixer" - v0.2pre - 12/15/2010 * http://benalman.com/projects/jquery-misc-plugins/ * * Copyright (c) 2010 "Cowboy" Ben Alman * Dual licensed under the MIT and GPL licenses. * http://benalman.com/about/license/ */ (function($){ var // RegExp that matches opening and closing HTML, HEAD, BODY tags.
<!DOCTYPE html> <html> <head> <script src="jsonp.js"></script> <script> document.addEventListener("DOMContentLoaded", function() { var requestUrl = "http://en.wikipedia.org/w/api.php?action=parse&page=Dog&format=json"; getJsonp({ url: requestUrl,
// Want to learn more about Immediately Invoked Function Expressions? Read // this article first: // // http://benalman.com/news/2010/11/immediately-invoked-function-expression/ // Parens are used to tell the parser that it's a function expression, // not a function declaration. If you don't explicitly tell the parser to // expect an expression, it will throw a SyntaxError exception because it // sees a function declaration without a name specified. (function(){ /* code */ })() // I've been using this one (function(){ /* code */ }()) // Crockford recommends this one
/*! * JavaScript whatevCache - v0.2pre - 12/30/2010 * http://benalman.com/ * * Copyright (c) 2010 "Cowboy" Ben Alman * Dual licensed under the MIT and GPL licenses. * http://benalman.com/about/license/ */ // whatevCache.set( key, value [, ttl ] ); // (returns undefined on success, error object otherwise) //
function Human(){ var that = this; var name="John Doe"; that.getName=function(){return name;} that.setName=function(value){name=value;} return that; } function Man(){ var that = this.prototype = new Human(); this.prototype.constructor = Man;
function domReady(callback) { var domLoaded; var called; var onReadyStateChange = function () { if (document.readyState == 'complete') { domLoaded(); } }; var interval;
<!DOCTYPE html> <html> <head> <title>Dojo x-domain Skeleton</title> <script src="http://ajax.googleapis.com/ajax/libs/dojo/1.5/dojo/dojo.xd.js"></script> <script> // the superclass dojo.declare("Foo", null, { bar:function(){ console.warn("Foo's bar"); },
/*! * jQuery htmlDoc "fixer" - v0.2pre - 12/15/2010 * http://benalman.com/projects/jquery-misc-plugins/ * * Copyright (c) 2010 "Cowboy" Ben Alman * Dual licensed under the MIT and GPL licenses. * http://benalman.com/about/license/ */ (function($){ var // RegExp that matches opening and closing HTML, HEAD, BODY tags.
var supportedMimeTypes = ['video/mp4', 'video/x-ms-wmv']; var supportedVideoExtensions = ['.mp4', '.wmv', '.mp4v', '.m4v']; var getSupportedMediaSource = function(videoElement) { // If the video element source is supported, then we replace the tag. if (videoElement.src && isWMPSupported(videoElement)) { return videoElement.src; }
self calling worker
document.addEventListener( "DOMContentLoaded", function() { var selfy = selfish(); selfy.worker.addEventListener( "message", function( event ) { var data = event.data; console.log( data );
<!DOCTYPE html> <html> <head> <script src="renderer.js"></script> </head> <body> </body> </html>
<?php echo "Prepping CSS and JS for deploy...\n"; $css_files['app'] = array('reset', '960', 'screen', 'jquery.tagsinput', 'jquery.autocomplete', 'tipsy', 'prettify'); //$css_files['splash'] = array('reset', 'splash'); //$css_files['iphone'] = array('reset', 'screen', 'iphone'); $js_files['app'] = array('jquery.autocomplete.min', 'jquery.tagsinput', 'jquery.scrollTo-1.4.2-min', 'forrst', 'jquery.tipsy', 'jquery.autoresize.min', 'prettify', 'lang-apollo', 'lang-css',
; Just drop this in /etc/couchdb/local.d/ and then ; start CouchDB normally. ; Here couch_node can be anything as long as it's uniq. [os_daemons] couch_node = /Users/davisp/tmp/couch-node.js ; This section can be named anything but you should ; probably make it follow the os_daemon name we
// get the average color of two hex colors. function avgcolor(color1,color2){ var avg = function(a,b){ return (a+b)/2; }, t16 = function(c){ return parseInt((''+c).replace('#',''),16) }, hex = function(c){ return (c>>0).toString(16) }, hex1 = t16(color1), hex2 = t16(color2), r = function(hex){ return hex >> 16 & 0xFF}, g = function(hex){ return hex >> 8 & 0xFF}, b = function(hex){ return hex & 0xFF}, res = '#' + hex(avg(r(hex1),r(hex2))) + hex(avg(g(hex1),g(hex2)))
#!/bin/sh # phpinfo-mine # Finds and retrieves phpinfo() pages from Google results. # # Requires WhatWeb and gggooglescan in the current working directory. # # It is highly recommended that you change your passwords if your servers' # passwords appears in this list. ## # Google Results as at 2011-01-21 # # 52 results for intitle:"phpinfo()" "mysql.default_password" "Zend Scripting Language Engine" # 33 results for inurl:"phpinfo.php" intitle:"phpinfo()" "mysql.default_password"
#!/usr/local/bin/ruby require "socket" irc = TCPSocket.open('irc.freenode.net', 6667) irc.send("USER blah blah blah :blah blah\n", 0) irc.send("NICK ChanScanBot\n", 0) irc.send("JOIN #sproutcore\n", 0) names = [] until irc.eof? data = irc.gets
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>Text Editor</title> <meta name="generator" content="TextMate http://macromates.com/"> <meta name="author" content="Peter Wagenet"> <!-- Date: 2010-05-12 --> <script type="text/javascript" charset="utf-8" src="jquery-1.4.2.js"></script>
v8 = V8::Context.new v8["foo"] = proc do |hello| # can I get the JS callstack here? puts hello end v8.eval("function bar() { baz('sven' )}; function baz(name) { foo(name) }")
function pp (t) { if (typeof console == "object" && typeof console.log == "function") console.log(t); else print(t); }
var SerialPort = require("./serialport") var sp = new SerialPort("/dev/ttyUSB0") sp.write("OMG USB"); // Reading is not perfect yet sp.on('data', function(data) { sys.puts("data"); }); sp.close();
invoking call directly on a function expression
(function() { console.log(this); }).call({});