Created
February 21, 2010 16:26
-
-
Save peta/310397 to your computer and use it in GitHub Desktop.
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 repeat = 500; | |
// Using Crockford's Module Pattern | |
console.profile("Crockford's Module Pattern"); | |
var arrObjLit = [], | |
iObjLit = repeat; | |
while (iObjLit--) { | |
(function() { | |
var privVar = "privVal", | |
privVar2 = "privVal2", | |
privVar3 = "privVal3"; | |
function privMeth() { | |
//Foo | |
} | |
this.push({ | |
pubMeth: function() { | |
privMeth(privVar); | |
} | |
}); | |
}).call(arrObjLit); | |
} | |
while (++iObjLit < repeat) { | |
arrObjLit[iObjLit].pubMeth(); | |
} | |
console.profileEnd(); | |
// Instantiation of anonymous function instances | |
console.profile("anonymous function instances"); | |
var arrAnonFn = [], | |
iAnonFn = repeat; | |
while (iAnonFn--) { | |
arrAnonFn.push(new function() { | |
var privVar = "privVal", | |
privVar2 = "privVal2", | |
privVar3 = "privVal3"; | |
function privMeth() { | |
//Foo | |
} | |
this.pubMeth = function() { | |
privMeth(privVar); | |
}; | |
}); | |
} | |
while (++iAnonFn < repeat) { | |
arrAnonFn[iAnonFn].pubMeth(); | |
} | |
console.profileEnd(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment