I hereby claim:
- I am uri-chandler on github.
- I am uri_chandler (https://keybase.io/uri_chandler) on keybase.
- I have a public key ASCbMMnVpA2UroLrW9ICpfPjfH7Szmi_7rmgGFxSslTNPAo
To claim this, I am signing this object:
I hereby claim:
To claim this, I am signing this object:
I hereby claim:
To claim this, I am signing this object:
// using wait-sync, you can use both async *and* sync code in the same execution block | |
// without worring about blocking the thread (so node's event-loop keeps running, I/O still works as expected etc..) | |
var waitSync = require('wait-sync'); | |
// the easy part - just log "1" to the console | |
console.log(1); | |
// next, setup some async operation that will log "2" sometime in the future - say, 3 seconds from now | |
setTimeout(() => console.log(2), 3000); |
// In older IE, this function doesn't inherit from Function.prototype | |
// so there's no .apply() we can use. | |
// This will throw an error | |
document.getElementById.apply(document, ['myDiv']) // Error! | |
// The solution: | |
(Function.prototype.apply).apply(document.getElementById, [document, ['myDiv']]); // Smooth! |
function greet(name){ | |
console.log('hello ' + name); | |
} | |
// We usually invoke a function by writing it's name followed by parenthesis | |
greet('John'); // hello John | |
// Another way - using .apply() |
/** | |
* Example of loose coupling using events | |
*/ | |
function work(){ | |
this.emit('working'); | |
} | |
var shovel = { |
/** | |
* Example of loose coupling between work() and shovel.use() | |
*/ | |
function work(tool){ | |
tool.use(); | |
} | |
var shovel = { |
/** | |
* Example of tight coupling between work() and shovel.use() | |
*/ | |
function work(){ | |
shovel.use(); | |
} | |
var shovel = { |
(function(){ | |
// First, delete all cookies | |
var cookies = document.cookie.split(";"); | |
for (var i = 0; i < cookies.length; i++) { | |
var cookie = cookies[i]; | |
var eqPos = cookie.indexOf("="); | |
var name = eqPos > -1 ? cookie.substr(0, eqPos) : cookie; | |
document.cookie = name + "=;expires=Thu, 01 Jan 1970 00:00:00 GMT"; | |
} |
// Adds array-like accessors to 'obj' | |
function arrayify(obj){ | |
// Init | |
var newObj = {}, | |
idx = 0; | |
// Add array-like keys to all self-properties | |
for (var key in obj){ if (obj.hasOwnProperty(key)){ | |