This file contains 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 queue = function () { | |
this.items = []; | |
this.timer = null; | |
}; | |
queue.prototype = { | |
add: function (item) { | |
var self = this; | |
self.items.push(item); | |
}, |
This file contains 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
git config --global user.name "First Last" | |
git config --global user.email "[email protected]" | |
git config --global color.ui true | |
git config --global alias.lg "log --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr %an)%Creset' --abbrev-commit --date=relative" | |
git config --global alias.last 'cat-file commit HEAD' |
This file contains 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 RIM = RIM || {}; | |
RIM.com = RIM.com || {}; | |
RIM.com.alice = RIM.com.alice || {}; | |
RIM.com.alice.hello = function () { | |
console.log('Hello World!'); | |
}; | |
(function() { | |
// save a local reference to namespace objects |
This file contains 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 Person = function (name) { | |
this.name = name; | |
}; | |
Person.prototype = { | |
says: function (saying) { | |
console.log(this.name + ' says "' + saying + '"'); | |
} | |
}; |
This file contains 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
for (var i = 0; i < 10; i++) { | |
var link = document.createElement("a"); | |
link.innerHTML = "Link " + i; | |
link.href = "#"; | |
link.onclick = (function (num) { | |
return function () { | |
alert("This is link " + num); | |
return false; | |
}; | |
}(i)); |
This file contains 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 fibonacci = (function () { | |
var cache = {}; | |
return function (n) { | |
if (cache[n]) { | |
return cache[n]; | |
} | |
//console.log("Solving for " + n); | |
var result; |
This file contains 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 getElement = function () { | |
console.log("Creating element"); | |
var elem = document.createElement("div"); | |
// do a bunch of expensive operations | |
// overwrite function with a simpler version | |
getElement = function () { | |
return elem; | |
}; |
This file contains 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 myObject = { | |
someProperty: 42 | |
}; | |
myObject.method = function () { | |
console.log(this.someProperty); | |
}; | |
function bindContext (func, context) { | |
return function () { |
This file contains 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 myObject = { | |
someProperty: 42 | |
}; | |
function adder (num1, num2) { | |
return this.someProperty + num1 + num2; | |
} | |
console.log(adder.call(myObject, 10, 20)); // 72 | |
console.log(adder.apply(myObject, [10, 20])); // 72 |
This file contains 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
// creating a function with a dynamic function body | |
var Product = new Function("x", "y", "return x*y;"); // avoid unless you have to because it uses eval on 3rd arg |
OlderNewer