TIL
TIL copied to clipboard
bind, 函数的第二个参数会输出什么?
今天看到一个地方有误解,自己试了下,感觉挺不错。
你觉得下面的这个console
的saga
会输出什么?
function run({name, age}, saga, ...options){
console.log('name is', name, 'saga is', saga)
}
let boundRun = run.bind(null, {name: 'xiaohesong', age: 18})
function *rootSaga() {
yield 'i am a generator function'
}
boundRun(rootSaga)
来实现个bind函数。
bind = (fn, _this, ...bindArgs) => (...args) => fn.apply(_this, [...bindArgs, ...args])