@Gildas
I think that's incredibly useful information. Thanks for the link!
What about "building" an object? I don't know whether to call it
object-composition or the object-factory pattern, but don't libraries
use this to provide advanced object-inheritance features? I've always
felt this would be incredibly slow - compared to using the prototyype
chain or assigning privileged methods within a constructor.
How fast is it to return created objects? (I'm not even sure if this
is how the object-factory pattern works exactly - that is, without the
"new" operator.) Could you add something like this to your tests?
(function () {
var MyClass = {},
_privateFunction = function () {
return this._privateVar;
},
publicMethod = function publicMethod() {
return this._privateFunction();
};
MyClass.create = function () {
var obj = {};
obj._privateVar = 42;
obj._privateFunction = function () {
return _privateFunction.apply(obj, arguments);
};
obj.publicMethod = function () {
return publicMethod.apply(obj, arguments);
};
return obj;
};
window.MyClass3 = MyClass;
)();
On Apr 28, 2:23 pm, Gildas <[email protected]> wrote:
> This thread gave me the idea to compare performances of 2 ways of
> creating objects :
> - by adding methods to prototype object
> - by adding methods directly to the new object (but function
> definitions are not copied and parsed for each new object)
>
> The majority of modern browsers give better results when adding
> members to prototype object but it also depends on method calls
> number. BTW, I think V8 guys have found a great optimization in chrome
> 13...
>
> Here is the test :http://jsperf.com/prototype-members-vs-instance-members/2
--
To view archived discussions from the original JSMentors Mailman list:
http://www.mail-archive.com/[email protected]/
To search via a non-Google archive, visit here:
http://www.mail-archive.com/[email protected]/
To unsubscribe from this group, send email to
[email protected]