Javascript 将函数作为参数传递给bind如何工作?
阅读《你不知道JS系列》时,你被下面的片段弄糊涂了Javascript 将函数作为参数传递给bind如何工作?,javascript,Javascript,阅读《你不知道JS系列》时,你被下面的片段弄糊涂了 function spread(fn) { return Function.apply.bind( fn, null ); // How does this work??? } Promise.all( foo( 10, 20 ) // Returns an array of promises ) .then( spread( function(x,y){ console.log( x, y );
function spread(fn) {
return Function.apply.bind( fn, null ); // How does this work???
}
Promise.all(
foo( 10, 20 ) // Returns an array of promises
)
.then(
spread( function(x,y){
console.log( x, y ); // 200 599
} )
)
试图理解将函数传递到bind将如何更改其数组参数?注意,我们在这里绑定了一个要应用的函数,因此我们用一个带参数的函数替换了一个应用函数…,这个参数专门讨论了这个绑定