【发布时间】:2017-07-09 16:26:14
【问题描述】:
当我尝试通过this 关键字访问时遇到问题。我需要在updateTime 中访问run 函数
export class PlayerService {
createPlayer(): void {
return new window['YT'].Player(this.youtube.playerId, {
height: this.youtube.playerHeight,
width: this.youtube.playerWidth,
events: {
'onStateChange': (event) => {
function updateTime() {
//////I need to access | run function | from here
};
this.timeupdater = setInterval(updateTime, 100);
}
}
});
}
run (){
//some codes
}
}
我正在研究 ionic 2
【问题讨论】:
-
您能否更新您的问题以显示所有代码和失败?
-
确保
updateTime也使用箭头函数 -
@Bergi 是的,这就是问题所在,我之前对此一无所知(问题是我必须在两者中都使用箭头),但我不明白这怎么可能是重复的问题?与您的评分问题没有任何关系:)
-
@programmer 当然是。它解释了(所有方式)如何访问像
updateTime这样的函数中的this值,您将其作为回调传递给某些东西(在您的示例中为setTimeout),以及为什么它不适用于function.
标签: javascript angular function typescript ionic-framework