Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/432.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 将函数作为参数传递给bind如何工作?_Javascript - Fatal编程技术网

Javascript 将函数作为参数传递给bind如何工作?

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 );

阅读《你不知道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 );    // 200 599
    } )
)

试图理解将函数传递到bind将如何更改其数组参数?注意,我们在这里绑定了一个要应用的函数,因此我们用一个带参数的函数替换了一个应用函数…

,这个参数专门讨论了这个绑定