Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bind, 函数的第二个参数会输出什么? #16

Open
xiaohesong opened this issue Dec 13, 2018 · 1 comment
Open

bind, 函数的第二个参数会输出什么? #16

xiaohesong opened this issue Dec 13, 2018 · 1 comment
Labels
function rewrite 重写一些原生方法 tips 一些不错的想法

Comments

@xiaohesong
Copy link
Owner

今天看到一个地方有误解,自己试了下,感觉挺不错。

你觉得下面的这个consolesaga会输出什么?

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)
@xiaohesong xiaohesong added tips 一些不错的想法 function labels Dec 13, 2018
@xiaohesong
Copy link
Owner Author

来实现个bind函数。

bind = (fn, _this, ...bindArgs) => (...args) => fn.apply(_this, [...bindArgs, ...args])

@xiaohesong xiaohesong changed the title 函数的第二个参数会输出什么? bind, 函数的第二个参数会输出什么? Dec 28, 2018
@xiaohesong xiaohesong added the rewrite 重写一些原生方法 label Dec 28, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
function rewrite 重写一些原生方法 tips 一些不错的想法
Projects
None yet
Development

No branches or pull requests

1 participant