0
点赞
收藏
分享

微信扫一扫

JavaScript new一个对象发生了什么

Java旺 2021-09-30 阅读 63
前端
function Mother(lastName) {
  this.lastName = lastName
}
let son = new Mother('技术蛋老师')

1.创建一个新对象son
2.新对象会被[[prototype]]原型对象连接起来
son.__proto__ === Mother.prototype // true
3.新对象和函数调用的this会绑定起来
Mother.call(son, '技术蛋老师')
4.执行构造函数中的代码
son.lastName
5.如果函数没有返回值,那么就会自动返回这个新对象

举报

相关推荐

0 条评论