【JavaScript】new 操作符
文章目录
new 的使用
function Student(name) {
this.name = name
}
var stu = new Student('tao')new 的原理
function Student(name) {
// js 会创建临时对象保存 stu 的属性
// var temp = {}
// 改变 this 指向
// this = temp
// 改变原型
// this.__proto__ = Student.prototype
this.name = name
// 然后返回 这个 stu
// return this
}
评论
登录后参与技术讨论,分享你的经验与见解。
登录 / 注册暂无评论