var Obj = function(msg){ this.msg = msg; this.shout = function(){ console.log(this.msg); } this.waitAndShout = function(){ setTimeout(function () { this.shout(); }.call(this),200); } }; var obj = new Obj('haha'); obj.waitAndShout();
obj对象调用了waitAndShout,所以waitAndShout中的this指向obj,而setTimeout第一个参数的函数this被call指向了外层作用域的对象,即obj对象,所以打印出haha。这里如果不加.call(this),就会报错this.shout is not a function。