This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
HAI | |
CAN HAS STDIO? | |
I HAS A VAR | |
IM IN YR LOOP | |
UP VAR!!1 | |
VISIBLE VAR | |
IZ VAR BIGGER THAN 10? KTHXBYE | |
IM OUTTA YR LOOP | |
KTHXBYE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//one statement - all on one line - good for short, similar purpose vars | |
var foo = [], bar = [], buzz = []; | |
//multiple var statements - good for large number or disperate purpose vars | |
var a = 12; | |
var collate = false; | |
var foo = [1,2,3,4]; | |
var circle = {radius: 2, color: blue}; | |
//one statement on multiple lines, no indent |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//generic circle functions | |
var asCircle = function() { | |
this.area = function() { | |
return Math.PI * this.radius * this.radius; | |
} | |
this.grow = function() { | |
this.radius++; | |
} | |
this.shrink = function() { | |
this.radius--; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* probably not good practice to attach event handlers to the <html> element but... | |
*/ | |
//IE < 9 throws operation not supported error just on property existence check (not function invocation) | |
typeof $('html')[0]; //"unknown" | |
$('html')[0].removeAttribute //throws operation not supported error | |
/************************************************/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Conditionals | |
( false :) | |
console.log "if" | |
:( true ) | |
console.log "else if" | |
:() | |
console.log "else" | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Iterates every Math function in random order, with random arguments, | |
then randomly adds or subtracts each result and rounds the grand total. | |
Typical output: | |
+ tan(9) | |
+ sqrt(0) | |
- sin(0) | |
+ random() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
main() { | |
print((function(x) => x + 1)(multiply(6, 6))); | |
} | |
var multiply = function(a, b) {return a * b;}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var NodeList = function() {}; | |
var nodeListExtras = {x: 23}; | |
mixin(NodeList.prototype, Array.prototype, nodeListExtras); | |
function mixin(obj /*, mixins*/) { | |
var mixins = [].slice.call(arguments, 1); | |
for (var i=0; i<mixins.length; i++) { | |
var thisMixin = mixins[i]; | |
var props = Object.getOwnPropertyNames(thisMixin); | |
for (var j=0; j<props.length; j++) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function func(a, f) { | |
return function (args) { | |
args = args || {}; | |
args.__proto__ = a; | |
f.call(this, args); | |
}; | |
}; | |
var f = func({foo : 10, bar : 20}, function (args) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function mixin(obj, fn) { | |
fn.call(obj); | |
} | |
//this gets bound dynamically | |
var withCircleUtils = function() { | |
this.area = function() {return this.radius * this.radius * Math.PI}; | |
this.diameter = function() {return this.radius + this.radius}; | |
} |
OlderNewer