- GitHub Staff
- https://josh.black
- @josh.black
- @__joshblack
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
<div class="foo"></div> | |
<script> | |
document.querySelectorAll('.foo').addEventListener('click', function() { | |
console.log('You clicked me!'); | |
}); | |
// Or in jQuery | |
$('.foo').on('click', function() { | |
console.log('You clicked me!'); |
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
<ul> | |
<li>1</li> | |
<li>2</li> | |
<li>3</li> | |
<li>4</li> | |
<li>5</li> | |
<!-- ... --> | |
</ul> | |
<script> |
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
<ul> | |
<li>1</li> | |
<li>2</li> | |
<li>3</li> | |
<li>4</li> | |
<li>5</li> | |
<!-- ... --> | |
</ul> | |
<script> |
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 addSecretSalt() { | |
var secret = "JS Rules!"; | |
return function(salt) { | |
return secret + salt; | |
} | |
}; | |
// Usage | |
var secretAndSalt = addSecretSalt('salted'); // "JS Rules!salted" |
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 fs = require('fs'); | |
fs.readFileAsync('foo.txt', function(buffer) { | |
var fileContents = buffer.toString(); | |
// do stuff! | |
}); |
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
// Using jQuery... | |
$('.foo').on('click', function() { | |
// do stuff! | |
}); |
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 = {}; | |
MODULE.submodule = (function() { | |
function init() { | |
console.log('initiated!'); | |
}; | |
return { | |
init: init | |
}; |
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
// Composition | |
function add(x) { | |
return function(y) { | |
return x + y; | |
}; | |
}; | |
// Usage | |
add(1)(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
function foo() {}; | |
foo.call(thisArg, arg1, arg2, arg3, /* ... */); | |
foo.apply(thisArg, [arg1, arg2, arg2, /* ... */]); |
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() { | |
console.log(x); // undefined | |
var x = 1; | |
console.log(x); // 1 | |
}; | |
// What actually happens under the hood | |
function foo() { | |
var x; |