我有下一段代码:
function Server() {
this.isStarted = false;
// var isStarted = false;
function status() {
return isStarted;
}
console.log(status());
}
var a = new Server()
当我运行它时,我得到
ReferenceError: isStarted is not defined
at status (/a/fr-05/vol/home/stud/yotamoo/workspace/ex4/text.js:7:10)
at new Server (/a/fr-05/vol/home/stud/yotamoo/workspace/ex4/text.js:10:14)
at Object.<anonymous> (/a/fr-05/vol/home/stud/yotamoo/workspace/ex4/text.js:
但是,如果我更改this.isStarted = false;
为var isStarted = false;
一切正常。
有人愿意解释为什么吗?
谢谢