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
| DEFAULTS = { | |
| color: "blue", | |
| border: 0, | |
| width: '128px', | |
| height: '128px' | |
| }; | |
| function mergeOptions (defaults, options) { | |
| for (var name in defaults) { | |
| if (defaults.hasOwnProperty(name)) { |
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 setBG (options) { | |
| var args = { | |
| red: 255, | |
| green: 255, | |
| blue: 255 | |
| } | |
| // overwrite defaults | |
| for (var i in options) { | |
| args[i] = options[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
| function say (name, agree) { | |
| // provide default values | |
| var name = name || "Fred"; | |
| var agree = (agree !== undefined) ? true : false; | |
| } | |
| say(); // Fred, false | |
| say("Barney"); // Barney, false | |
| say("Barney", "anything"); // Barney, true |
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 () { | |
| // self-invoking 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
| function outerFunction () { | |
| return function () { | |
| // anonymous inner 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
| function getStockQuote() { | |
| var xhr; | |
| if (window.XMLHttpRequest) { | |
| xhr = new XMLHttpRequest(); | |
| } | |
| else { | |
| xhr = new ActiveXObject("Microsoft.XMLHTTP"); | |
| } | |
| xhr.onreadystatechange = 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
| // object literal | |
| var myObj = { | |
| property1: 42, | |
| property2: "Hello", | |
| property3: true | |
| }; | |
| // loop over properties | |
| for (var i in myObj) { | |
| console.log(i + ': ' + myObj[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
| // add items | |
| [1, 2, 3].concat([4, [5, 6]]); // [1, 2, 3, 4, 5, 6] | |
| [1, 2, 3].push([4, [5, 6]]); // [1, 2, 3, 4, [5, 6]] | |
| [1, 2, 3].unshift([4, [5, 6]]); // [4, [5, 6], 1, 2, 3] | |
| // remove items | |
| [1, 2, 3].pop(); // [1, 2] | |
| [1, 2, 3].shift(); // [2, 3] |
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
| escape(str) | |
| unescape(str) | |
| encodeURI(str) | |
| decodeURI(str) | |
| encodeURIComponent(str) | |
| decodeURIComponent(str) | |
| var url = "http://finance.yahoo.com/q?s=RIM.TO&ql=0"; |
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
| "abcde".charAt(3); // d | |
| "abcde".charCodeAt(0); // 100 = d | |
| String.fromCharCode(100); // d | |
| "abcde".slice(0, 2); // ab | |
| "abcde".slice(1, -1); // bcd | |
| "abcde".slice(-2); // de | |
| "abcde".substr(0, 2); // ab | |
| "abcde".substr(1, 3); // bcd |