Please look at the code below:
function Foo() {}
Foo.prototype.toString = function toString() {
return "[object Foo]";
}
var a = new Array();
var f = new Foo();
alert(a.toString()); // alerts [object Array]
alert(f.toString()); // alerts [object Foo]
alert(Object.prototype.toString.call(a)); // alerts [object Array]
alert(Object.prototype.toString.call(f)); // alerts [object Object]
Why f.toString() and Object.prototype.toString.call(f) have different results? And why a.toString() and Object.prototype.toString.call(a) have the same results?
How do I implement Foo.prototype.toString to return [object Foo] on call Object.prototype.toString? How to get the same behavior as on native types (Array, Date, Boolean etc.)
Sorry for my bad English...