function fn(){
console.log(this) //Window 严格模式下指向undefied 非严格模式下指向Window
}
fun()
function fn(){
console.log(this) // fn{}
}
new fn()
1.通过使用new关键词 函数的内部生成一个全新的对象 函数的this指向这个对象
function fn() {
console.log(this)
}
console.log(fn()); // undefined 函数自执行 结果返回undefined
function fn(){
this.x = 10;
}
console.log(new fn()) // fn {x:10}
2.通过new 执行 函数默认返回上述对象