下面我有麻煩女巫功能:通JS變量從jquery的
inactive() {
let target = $('.album__item--cover-container');
var leave:boolean;
target.mouseleave(function() {
leave = true;
console.log("LEAVE MOUSEENTER: ", leave);
});
console.log("LEAVE: ", leave);
if (leave) {
console.log("LEAVE CONDITION: ", leave);
this.flyOut = 'inactive';
}
console.log(this.flyOut);
}
我不知道西隧日誌"LEAVE MOUSEENTER"
是真實的,從鼠標事件退出後登錄"LEAVE
「是undefined
我不能在這個事件函數declate this.flyOut = true
。請人helop我,並解釋爲什麼這種行爲去呀?
問候 格雷格
也許這是範圍問題。你可以使用箭頭功能嗎? targer.mouseleave(()=> {...})。也許改變var讓 – Kyrsberg
你是對的。缺少.bind(this)賦值,默認情況下哪些箭頭函數具有。謝了哥們! –