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:
- if type(v) not object, return false.
wiki
Comments
Post a Comment