Here is a question in JavaScript below:
// Tested via Google Chrome console.
var toString = Object.prototype.toString;
"foo".toString(); // "foo"
toString.call("foo"); // [object String]
[].toString(); // ""
toString.call([]); // [object Array]
{}.toString(); // syntax error
toString.call({}); // [object Object]
Why the result of toString is different with toString.call() ?
UPDATED
String.prototype.toString.call("foo"); // "foo"
Object.prototype.toString.call("foo"); // [object String]
Is String.prototype.toString not from the prototype chain like below?
toString in String[not found] --> toString in String.prototype[not found]
--> toString in Object.prototype[found]
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…