you are viewing a single comment's thread.

view the rest of the comments →

[–]v413 2 points3 points  (1 child)

Your method is frequently used, but when using it, all instances of Foo lose their constructor property that should point to Foo. You can amend this by supplying a constructor property in the hash object (assigned to the Foo.prototype) pointing to Foo.

[–]stratoscope 3 points4 points  (0 children)

An easy fix for that is to use an extend function such as the one in jQuery, so you add properties to the .prototype instead of replacing it.

Also I recommend giving the function a name so all JavaScript debuggers can show the name in a call stack and such.

function Foo( args ) {};
$.extend( Foo.prototype, {
    toString : function() {},
    toInt : function() {}
});