Last active
August 29, 2015 14:14
-
-
Save DronRathore/19e1d4f5aeb373f0380a to your computer and use it in GitHub Desktop.
Call vs Apply
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 classA = function(options){ | |
if (this instanceof classA){ | |
this.options = options; | |
return this | |
} else { | |
return new classA(options) | |
} | |
} | |
classA.prototype.someAsnyc = function(callback, flag){ | |
if (!flag) | |
callback.apply(this); | |
else | |
callback.call(this); | |
if (!this.options.c) | |
console.log("Not Found"); | |
} | |
console.log("Started at:", (apply_date=Date.now())); | |
for (var i=0;i<10000000000;i++){ | |
var someObj = new classA({a:1, b: "Some String"}); | |
someObj.someAsnyc(function(){this.options.c="OK"}); | |
//someObj = undefined; //You can uncomment this if you are concerned about GC cycles | |
} | |
console.log("Apply Ended at:", (call_date=Date.now()), Date.now()-apply_date); | |
for (var i=0;i<10000000000;i++){ | |
var someObj = new classA({a:1, b: "Some String"}); | |
someObj.someAsnyc(function(){this.options.c = "Yo!";}, true); | |
//someObj = undefined; //You can uncomment this if you are concerned about GC cycles | |
} | |
console.log("Call Ended at:",Date.now(), Date.now()-call_date) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment