this 显示绑定

mac2022-06-30  67

function foo (el) { console.log(el, this.id); } var obj = { id: 'aaa' }; [2,6,3].forEach(foo, obj);

2aaa 6aaa 3aaa

通过call()、apply()进行绑定

转载于:https://www.cnblogs.com/wzybnzy/p/7216456.html

最新回复(0)