javascript - isPrototypeOf and __proto__ have different results -




the following 2 expressions:

"abc".__proto__.__proto__ === object.prototype  // true object.prototype.isprototypeof("abc")           // false 

the first expression proves object.prototype lies in prototype chain of "abc". however, second expression gets opposite result.

i confused. hope can explain.

"abc" not object. when evaluate "abc".__proto__, string wrapper object implicitly constructed retrieve prototype of, , object.prototype in wrapper object's prototype chain.

object.prototype.isprototypeof("abc") doesn't construct wrapper object. looks @ "abc", sees "abc" isn't object , has no prototype chain, , returns false. can see in ecmascript spec (version 6):

when isprototypeof method called argument v, following steps taken:

  1. if type(v) not object, return false.




wiki

Comments

Popular posts from this blog

Asterisk AGI Python Script to Dialplan does not work -

python - Read npy file directly from S3 StreamingBody -

kotlin - Out-projected type in generic interface prohibits the use of metod with generic parameter -