So when I make a library, I usually do it in this fashion:
var myLib = (function() {
return {
publicProperty: 'test',
publicMethod: function() {
console.log('public function');
},
anotherMethod: function() { //... },
// .. many more public methods
};
}());
I had overheard that creating libraries is faster and/or uses less memory for initialization if you write it like this:
var MyLib = function() {
this.publicProperty = 'test';
};
MyLib.prototype = {
publicMethod: function() {
console.log('public method');
},
anotherMethod: function() { //... },
// ... many more public methods
};
myLib = new MyLib();
Does one initialize faster than the other? Does my question even make sense? I assume that these accomplish the same task (that task being I go and use myLib.publicMethod()
somewhere else in my code on docready). Thanks!