原型链加强练习

1.new一个函数的时候发生了什么


new一个构造函数本质就是实例化一个对象


1.新建一个对象
2.constructor.call(新建的对象)
3.把函数的prototype属性赋值给新建的对象的__proto__

 

2.初始化一个函数的时候发生了什么?

function a() { }
声明了一个为a的函数


JavaScript解释器构造函数对象a
在a内部初始化一个属性prototype


prototype指向一个原型对象,

{

  constructor://a本身

  __proto__:Object

}


3. 如何在JavaScript中实现继承

function father(name){
this.name = name
}

let father = new father()

function Son(name){
father.call(this,name)
}

Son.prototype = Object.create(father.prototype)

son.prototype.constructor = son

 

// new Son('儿子')

 

 

posted @ 2019-03-08 21:04  hh9515  阅读(233)  评论(0编辑  收藏  举报