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 mycallback; | |
function foo() { | |
var x, y, z; | |
function bar() {/* something with x, y, and z*/} | |
mycallback = bar; | |
}; |
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
NaN === NaN; // false | |
NaN + 1; // NaN | |
NaN = 1; | |
NaN === NaN; // true | |
NaN + 1; // 2 | |
typeof undefined; // "undefined" | |
undefined = 1; | |
typeof undefined; // "number" |
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 ids = ["elem1", "elem2", "elem3"...], | |
i, | |
l = ids.length; | |
for (i = 0; i < l; i += 1) { | |
(function (i) { | |
$("#" + ids[i]).bind("click", function () { | |
alert(i); | |
}); | |
}()); |
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 MYGLOBAL = (function () { | |
var that = {}, | |
privateVariable = 2; | |
function privateFunction() { | |
//... | |
} | |
that.publicFunction = function () { | |
// |
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 foo = { | |
bar: "foobar", | |
func: function () { | |
return this.bar; | |
} | |
}; | |
foo.func(); // "foobar" | |
var functionReferences = {}; |
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 foo(one, two, three) { | |
one = one || "defaultvalue"; // assigns default value if one is falsy (null, undefined, 0, "0", false, etc.) | |
two = two == null ? "defaultvalue" : two; // assigns default value if 'two' is not null or undefined (so you can pass things like 0 or false) | |
three = three === undefined ? "defaultvalue" : three; // assigns default value if three is not undefined (so you can pass null) | |
} |
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 module = (function () { | |
var my = {}, | |
privateStaticModuleVariable = "something"; | |
my.publicStaticObjectConstructor = function () { | |
var that = {}, | |
privateInstanceVariable = "something"; | |
that.publicInstanceVariable = "something"; | |
function privateInstanceFunction() {} |
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 performance = (function () { | |
var my = {}; | |
// Wrap a function body in this to return a copy that instruments itself | |
// If you want this to be useful, you should give your profiled function a name, | |
// otherwise it will be identified as "", which is less than useful. | |
my.profile = function (func) { | |
return function () { | |
var start = new Date().getTime(), | |
time, |
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
// Simple arithemetic parser. | |
// Follows order of operations, only supports positive integers | |
// Only operators are +, -, *, and /. Does not support grouping with () | |
var calc = (function () { | |
var calc, | |
sum, | |
negasum, | |
product, | |
dividend; | |
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 foo, bar; | |
foo = function () { | |
bar(); | |
} | |
bar = function () { | |
foo(); | |
} |
OlderNewer