将函数绑定到javascript中的另一个函数

Loo*_*urr 6 javascript bind function

我在javascript中有一个功能

function foo(callback) {
    console.log("Hello");
    callback();
}
Run Code Online (Sandbox Code Playgroud)

和另一个功能

function bar() {
  console.log("world");
}
Run Code Online (Sandbox Code Playgroud)

我想做一个功能 FooBar

FooBar = foo.bind(this, bar);
Run Code Online (Sandbox Code Playgroud)

这工作正常,但我实际上要做的是创建一个函数队列,并且在绑定回调之前我经常需要绑定一个none函数参数,如下例所示

function foo() {
    console.log(arguments[0]);
    var func = arguments[1];
    func();
}

function bar() {
    console.log("world");
}

foo.bind(this, "hello");
var FooBar = foo.bind(this, bar);

FooBar();
Run Code Online (Sandbox Code Playgroud)

这会产生这个错误

[Function: bar]

TypeError: undefined is not a function
Run Code Online (Sandbox Code Playgroud)

一旦将函数绑定到其他函数类型,我如何将函数绑定到另一个函数?

Ric*_*dle 5

要绑定"Hello"foo,然后分别结合barfoo,以及-你不应该绑定bar到第一的结果bind,就像这样:

var FooHello = foo.bind(this, "hello");
var FooBar = FooHello.bind(this, bar);
Run Code Online (Sandbox Code Playgroud)

在这里小提琴 (记录"你好","世界").