call()、bind()、apply()的用法,改變this的指向,區別在于
f.call(obj, arg1, arg2...),
f.bind(obj, arg1, arg2,...)(),
f.apply(obj, [arg1, arg2, .])
- apply
12345
function bindThis(f, oTarget) {returnfunction() {returnf.apply(oTarget, arguments)}} - bind
123
function bindThis(f, oTarget) {returnf.bind(oTarget)} - call
12345
function bindThis(f, oTarget) {returnfunction() {returnf.call(oTarget, ...arguments)}}
浙公網安備 33010602011771號