0
我目前偶然發現綁定的問題,我相信它會降低我的性能。在每次遞歸調用綁定看起來都很糟糕。優雅和高性能替代綁定()
林目前正在尋找處理這種情況的優雅和高性能的方式:
什麼是在這種情況下,理想是什麼?
class AlotMonster {
constructor() {
this.names = ['a lot', 'alot'];
this.method();
}
method() {
let choice = Math.round(Math.random());
let currentName = this.names[choice];
console.log(currentName);
requestAnimationFrame(this.method.bind(this));
}
}
new AlotMonster();
在構造'this.boundMethod =這只是把它一次。 method.bind(this);'並在隨後的調用中使用'this.boundMethod'。 – georg
@georg認真嗎?沒有想過它 – Asperger
@georg這可能是一個問題performancewise?綁定我的意思是 – Asperger