new是怎么使用的
1.创建一个空对象,把这个对象的__proto__赋值为fn.prototype==>{proto:fn.prototype}
2.执行fn函数 fn函数内部的this代表创建出来的这个对象
3.fn函数的返回值是基本数据:表达结果就是创建的对象 引用数据的话,表达式结果就是fn的返回值
function fn () {
this.name="Alice"
this.say=function () {
console.log("1212")
console.log(this)
}
}
var re=new fn()//使用new创建对象
console.log(re)//{__proto__:{},name:"Alice",say:func}
var fm=re.say
fm()//1212 ,{__proto__:{},name:"Alice",say:func}
re.say()//1212,window