Skip to content

Instantly share code, notes, and snippets.

@surjikal
Created October 23, 2012 16:44
Show Gist options
  • Save surjikal/3939997 to your computer and use it in GitHub Desktop.
Save surjikal/3939997 to your computer and use it in GitHub Desktop.
Javascript Tests
function decorator(fn) {
function wrapper() {
console.log('Before function.');
var ret = fn.apply(this, arguments);
console.log('After function.');
return ret;
}
return wrapper;
}
function foo(msg) {
console.log("[foo]", msg);
}
decorator(foo)('Hello there!');
// These actually are valid!
// see http://mathiasbynens.be/notes/javascript-identifiers
var ಠ_ಠ = eval;
var Σ = function(arr) {
return arr.reduce(function(previous, current) {
return previous + current
}, 0);
}
console.log( Σ([1,2,3]) ); // 6
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment