constobj= { name:'foo',sayMyName() {console.log('My name is',this.name) }}obj.sayMyName() //-> My name is fooobj.deb =debounce(obj.sayMyName,1000)obj.deb() // Should log -> My name is foo
在省略context的写法下,只能输出,因为My name isobj的this没有绑定进去。
除非使用
obj.deb =debounce(obj.sayMyName.bind(obj),1000)obj.deb() // now -> My name is foo