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 Cats() { | |
var names = []; | |
// Get the instance of the Cats class | |
// If there's none, instanciate one | |
var getInstance = function() { | |
if (!Cats.singletonInstance) { | |
Cats.singletonInstance = createInstance(); | |
} |
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 isHash(obj) { | |
return typeof(obj) == "object" && Object.prototype.toString.call(obj) != "[object Array]"; | |
} |
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
git submodule add git://github.com/[user]/[project].git [submodule path] |
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 myApplication = {}; | |
myApplication.instance = { | |
msg : "Hello world!", | |
hello : function() { | |
alert(myApplication.instance.msg); | |
} | |
} | |
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 instance = { | |
msg : "Hello world!", | |
hello : function() { | |
alert(instance.msg); | |
} | |
} | |
instance.hello(); |
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 myApplication = {}; | |
myApplication.instance = (function() { | |
var i = { | |
msg : "Hello world!", | |
hello : function() { | |
alert(i.msg); | |
} | |
}; | |
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 count = function countToTen(i) { | |
if (i <= 10) { | |
console.log(i); | |
count(i+1); // Call count with the power of closures | |
} | |
} | |
count(1); |
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 count = function countToTen(i) { | |
if (i <= 10) { | |
console.log(i); | |
countToTen(i+1); // You can cleanly call the named function | |
} | |
} | |
count(1); |
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 count = function(i) { | |
if (i <= 10) { | |
console.log(i); | |
arguments.callee(i+1); // this will throw an error on ECMAScript 5 strict | |
} | |
} | |
count(1); |
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 func = function f1() { | |
var subfunc = function f2() { | |
(function f3() { | |
console.trace(); | |
})() | |
} | |
subfunc(); | |
} | |
func(); |