$(document).ready(function() {1
function Test() {
this.testArray = ["hi", "bye", "ok", "lol"];
this.doStuff = function() {
//returns the value of the array
console.log(this.testArray);
setTimeout(function() {
//returns undefined.
console.log(this.testArray);
}, 0.12)
}
}
//instantiating a Test() object.
var t = new Test();
function update() {
//calls doStuff() on object t every 100 ms.
t.doStuff();
}
setInterval(update, 100);
当console.log(this.testArray)
正文中包含setTimeout
语句时,为什么此脚本会将this.testArray
作为undefined
返回,但它会返回console.log(this.testArray)
时分配的值{1}}语句在setTimeout
正文之外?