js原型链的领悟

1 String Number Object Boolean Array Function的原型执行的对应于其构造器创建的对象

String.prototype 指向 new String() 但String.proptotype.__prototype__指向Object.prototype   //Object.prototype.__prototype === null ; String.prototype instanceof Object === true

Object.prototype 指向 new Object() //同上

Boolean.prototype指向 new Boolean() //同上

Number、Array、Function //同上

//所有的对象都继承自原始对象
    //Object比较特殊,他的原型对象也就是原始对象
    //所以我们往往用Object.prototype表示原始对象
    Object.__prototype__ === Function.prototype
    Object.prototype === o.__proto__;//true
    Object.prototype === Object.__proto__.__proto__;//true
    Object.prototype === Function.__proto__.__proto__;//true

2 new Object()和Object()、相同 Function() 和 new Function() 相同; Number 和 new Number() 不同,String() 和 new String(); Boolean() new Boolean()

typeof Object() === typeof new Object() === 'object'

typeof Function() === typeof new Function() === 'function'

typeof Number() === 'number' === typeof 1而 typeof new Number() === 'object'

typeof String() === 'string' === typeof 'str' 而 typeof new String() === 'object'

typeof Boolean() === 'boolean' === typeof false 而 typeof new Boolean() === 'object'



猜你喜欢

转载自blog.csdn.net/menghu07/article/details/81051911
今日推荐