Last active
December 16, 2015 17:19
-
-
Save ryasmi/5469868 to your computer and use it in GitHub Desktop.
Things learned in JavaScript and they are good. Sourced mainly from Paul Irish (watched his video a while ago but I wanted to get it down in code).
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
// Asynchronous Recursion. | |
(function me() { | |
doStuff(); | |
setTimeout(me, 100); | |
}()); | |
// (1) Better than the alternative that never ends. | |
setInterval(function () { ... }, 100); | |
// Ajax example. | |
(function loopsiloopsiloo () { | |
doStuff; | |
$("#Update").load("awesomething.php", function () { | |
loopsiloopsiloo(); | |
}); | |
}()); |
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
// new Function. | |
var x = (new Function("return " + data))(); | |
// (1) Better than using eval. | |
var x = eval("(" + data + ")"); |
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
// Immediately-Invoked Function Expression (IIFE). | |
(function (window, document, undefined) { | |
... | |
}(this, this.document)); | |
// (1) When minified it becomes. | |
(function (A, B, C) { | |
... | |
}(this, this.document)); | |
// (2) Ensures that undefined comparisons are correct. For example you might have... | |
undefined = true; | |
// (3) Benefits scope traversal because it only had to search the local scope for the variable. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment