【发布时间】:2013-11-22 13:10:46
【问题描述】:
我有一个对象,其中有两个函数,我猜每个函数都有不同的 this 值:
custom_controls : {
play_pause : function () {
console.log(this); // object
videoPlayer.getIsPlaying(function (video_is_playing) {
if (video_is_playing) {
console.log(this); // window
videoPlayer.pause(true);
} else {
videoPlayer.play();
}
});
}
},
然后函数是这样调用的:
custom_controls.play_pause()
我听说你调用函数的方式表示this 的值。
所以我的问题是:这里发生了什么?我正在使用什么样的函数调用?以及每一项对this有何影响?
【问题讨论】:
-
我们不知道您是如何调用这些函数的,因为它们是在其他地方调用的。
-
我不知道你在尝试什么,但如果你想在其他函数中获取
this实例然后var that= this;然后在其他函数中使用that -
@KendallFrey 我已经更新了我如何调用该函数的问题。
-
很好,但它仍然缺少第二个的调用。
标签: javascript closures this scope