Created
July 25, 2013 02:39
-
-
Save amadeus/6076482 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// jshint unused:false | |
/* global console */ | |
var num = 1, | |
flt = 2.1, | |
neg = -1, | |
hex = 0xFF2200, | |
octal = -01234, | |
nan = NaN, | |
nll = null, | |
udf = undefined, | |
bTrue = true, | |
bFalse = false, | |
str = 'This is a string', | |
inf = Infinity, | |
math = num + flt - num * flt / num % flt, | |
arr, obj, MyClass, instance, flrd; | |
Function; | |
Boolean; | |
Object; | |
Array; | |
window.addEventListener('load', function(something){ | |
console.log('loaded'); | |
}, false); | |
arr = [num, 1, 2.0, 'str', {}, [1]]; | |
obj = { | |
// Key with a regex - that often breaks things | |
// key: /"/, | |
arr: [ | |
'this is a', | |
'multiline array definition' | |
], | |
obj: { | |
func: function(){} | |
}, | |
'stringed': true | |
}; | |
flrd = flt >> 0 << 1 | 1 & 2; | |
MyClass = function MyClass(name, options){ | |
this.name = name; | |
this.options = {}; | |
for (var item in options) { | |
this.options[item] = options[item]; | |
} | |
this.getName = this.getName.bind(this); | |
}; | |
MyClass.prototype.getName = function getName(){ | |
return this.name; | |
}; | |
// This is not a named function | |
MyClass.prototype.setName = function(name){ | |
this.name = name ? name : 'No Name Set'; | |
return this; | |
}; | |
// Testing multiline function calling | |
instance = new MyClass( | |
'John', | |
{ | |
obj: obj, | |
arr: arr | |
} | |
); | |
MyClass.call({}, 'Nameless'); | |
switch (instance.getName()) { | |
case 'John': | |
console.log('It\'s John!'); | |
break; | |
default: | |
console.log('Sorry, not John'); | |
} | |
if (true && true === true) { | |
console.log('true'); | |
} else if (false || false !== false) { | |
console.log('false'); | |
} else { | |
console.log('hum'); | |
} | |
for (var x = 1, b = 1000; x < b; x++) { | |
--num; | |
num--; | |
++num; | |
} | |
var a = 0; | |
do { | |
a++; | |
} while (a < 10); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment