为什么以下js代码不起作用?

Mat*_*xYo 2 javascript window requestanimationframe

代码

var x = {};

x.request = window.requestAnimationFrame;

function step(timestamp) {

    console.log('sth');
}

x.request(step);
Run Code Online (Sandbox Code Playgroud)

它返回:

NS_ERROR_XPC_BAD_OP_ON_WN_PROTO:WrappedNative原型对象上的非法操作

它应该使x.request与window.requestAnimationFrame一样工作.我需要它,因为我想做类似的东西:

x.request = window.requestAnimationFrame
                ||
            window.webkitRequestAnimationFrame
                ||
            window.mozRequestAnimationFrame;
Run Code Online (Sandbox Code Playgroud)

Poi*_*nty 6

尝试

x.request.call(window, step);
Run Code Online (Sandbox Code Playgroud)

那将确保那thiswindow.