JavaScript: toString

How did it happen Object.prototype.toString === toString? If I have this in a global area:

var toStringValue = toString.call("foobaz");

I would expect that to toStringValuebe a value window.toStringbecause it windowis the default area, right? Why toStringdoes it decide instead of Object.prototype.toStringinstead window.toString?

+3
source share
1 answer

The results you get will depend on the host environment. If I run this:

alert(toString === window.toString);
alert(toString === Object.prototype.toString);​

... in Chrome I get trueand falseaccordingly; on Firefox I get falseand false. IE gives trueand false , but as shown below.

window , , .:-) , toString.call("foobaz") IE, toString of window JavaScript call apply. ( , , ...)

+4

Source: https://habr.com/ru/post/1763835/


All Articles