首页 > 代码库 > js 原型链
js 原型链
console.log(typeof Object)//null var o = {} ,var obj = new Object, new Dog() console.log(typeof Function) console.log(typeof Number) console.log(typeof Boolean) console.log(typeof String) //除了undefined js 其余5中类型的封装类型本质都是函数 console.log(typeof undefined) console.log(typeof Date) console.log(typeof Array) console.log(Date.prototype) console.log(Object.prototype) console.log(Function.prototype)//function(){}
上面是迷惑你的,下面才是干货:
function Father(){ this.p = ‘p‘ } var f = new Father function Son(){ } //Son 构造函数的原型对象 指向了f //这样就继承了f 的p 属性 Son.prototype = f //Son 的实例中有一个__proto__记录了 原型对象 Son.prototype 也就是 对象f var s = new Son() console.log(s) //关键在于f 对象中也有一个 __proto__ 记录了它的原型对象 Father.prototype //..... 如此一层一层的实现了继承 //终点是 null 这就是传说中的无中生有吧 Object.prototype.__proto__
js 原型链
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。