There was a question on here already about overriding toString and the answer is this:
function Foo() {}
Foo.prototype.toString = function()
{
return "this is Foo";
}
however my question is:
is there a way to put this prototype override INSIDE of the object declaration like so:
function Foo() {
Foo.prototype.toString = function(){
return "this is Foo";
}
}
or like so:
var Foo = {
Foo.prototype.toString = function(){
return "this is Foo";
}
}
it's really weird/annoying to have to put the prototype outside of the object declaration, but maybe this is a quirk of JavaScript. I have been wondering this for awhile.
Aucun commentaire:
Enregistrer un commentaire