js里this是指向的调用的引用对象
test本来是构造函数 正常使用该 var test1=new test();这里直接使用了test(),所以test被window引用,然后test里的this就被window,导致this.go就成了window.go,所以就能直接使用go();
function test(name,age){
this.name=name;
this.age=age;
this.go=function(){
alert(this.name);
}
}
this.name="ni da ye";
test();
go();// ni da ye;
test本来是构造函数 正常使用该 var test1=new test();这里直接使用了test(),所以test被window引用,然后test里的this就被window,导致this.go就成了window.go,所以就能直接使用go();