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
| var module = (function () { | |
| var my = {}, | |
| privateStaticModuleVariable = "something"; | |
| my.publicStaticObjectConstructor = function () { | |
| var that = {}, | |
| privateInstanceVariable = "something"; | |
| that.publicInstanceVariable = "something"; | |
| function privateInstanceFunction() {} |
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
| 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 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
| var foo = { | |
| bar: "foobar", | |
| func: function () { | |
| return this.bar; | |
| } | |
| }; | |
| foo.func(); // "foobar" | |
| var functionReferences = {}; |
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
| var MYGLOBAL = (function () { | |
| var that = {}, | |
| privateVariable = 2; | |
| function privateFunction() { | |
| //... | |
| } | |
| that.publicFunction = function () { | |
| // |
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
| 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 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
| 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 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
| var mycallback; | |
| function foo() { | |
| var x, y, z; | |
| function bar() {/* something with x, y, and z*/} | |
| mycallback = bar; | |
| }; |
NewerOlder