Javascript setTimeout - undefined 不是函数

use*_*158 2 javascript timeout

这是我的原始代码:

Viewport = {
    rotate: function () {
        setTimeout(function () {
            this.startRotate();
        }, 1000);
    }    

    startRotate: function () {
        console.log('in')
    }
}
Run Code Online (Sandbox Code Playgroud)

当我尝试运行 setTimeout 时:

setTimeout(this.startRotate(), 2000);  
Run Code Online (Sandbox Code Playgroud)

它失败了,因为这样 setTimeoout 中的代码会立即运行..

在我的原始代码中,我得到“未定义不是函数”。

这是为什么?

Ale*_*tov 5

Viewport = {
    rotate: function () {
        var that = this;
        setTimeout(function () {
            that.startRotate();
        }, 1000);
    }    

    startRotate: function () {
        console.log('in')
    }
}
Run Code Online (Sandbox Code Playgroud)