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
define( | |
[], | |
function () { | |
var utils = { | |
//object properties | |
}; | |
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 withStorage() { | |
if (window.localStorage) { | |
localStorage.call(this); | |
} else if (document.documentElement.addBehavior) { | |
userData.call(this); | |
} else { | |
memory.call(this); | |
} |
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
//shim of ES5.1 internal ToPrimitive method | |
//see http://es5.github.com/#x9.1 | |
//assumes no hint argument (as is the case with == operands) | |
var ToPrimitiveNoHint = function(value) { | |
if (typeof value != 'object') { | |
return value; | |
} | |
if (typeof value.valueOf() != 'object') { | |
return value.valueOf(); |
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}; | |
} |
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
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
/* | |
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
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
/* | |
* 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
//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 |