我认为范围链会做出第一个“test = new test();”工作,但事实并非如此。为什么?JS - 范围链
var tool = new Tool();
tool.init();
function Tool(){
var test;
function init(){
//does not work, undefined
test = new Test();
//does work
this.test=new Test();
console.log(test);
}
}
function Test(){
}
编辑:通过不工作我的意思是,它说,测试 '未定义'
它应该。问题是,你想要做什么?你的代码意味着什么。 – iMoses
这里没有足够的代码来说明究竟发生了什么。如何调用init?你如何尝试访问'test'? – josh3736
“工作”是什么意思? –