Knockout.js knockoutjs函数参数排序

Knockout.js knockoutjs函数参数排序,knockout.js,Knockout.js,我想确认一下敲除js方法绑定中的参数顺序 情景a:如果我只发送$data和event,那么第一个参数是data,第二个参数是dom event <a data-bind="click: $root.myFunction.bind($data)" href="#">Add Sheet</a> self.myFunction = function (data, event) {} self.myFunction=函数(数据、事件){} 情景B:如果我发送了额外的参数,那

我想确认一下敲除js方法绑定中的参数顺序

情景a:如果我只发送$data和event,那么第一个参数是data,第二个参数是dom event

<a data-bind="click: $root.myFunction.bind($data)" href="#">Add Sheet</a>
self.myFunction = function (data, event) {}

self.myFunction=函数(数据、事件){}
情景B:如果我发送了额外的参数,那么$data将成为myFunction中的最后一个参数,而myparam保留“funnyworld”的值


self.myFunction=函数(myparam,data){}
我是否正确理解订单

<a data-bind="event: { 'click': myFunction.bind($data, 'param1', 'param2') }" href="#">Add Sheet</a>

var vm = {
    myFunction: function (firstParam, secondParam, data, e) { 
        console.log(firstParam);
        console.log(secondParam);
        console.log(data);
        console.log(e);
    }
};
ko.applyBindings(vm);


情景A:

$root.myFunction.bind($data)
$root.myFunction.bind($data, 'funnyworld')
将导致
myFunction
中的
this
成为当前视图模型(
$data
)。通常的参数也将通过Knockout传递,因此您的参数实际上是:

self.myFunction = function (arg1, arg2) {
      // this === $data
      // arg1 === $data
      // arg2 === event
}
情况B:

$root.myFunction.bind($data)
$root.myFunction.bind($data, 'funnyworld')
还会导致
myFunction
中的
this
成为当前视图模型(
$data
),但也会使第一个参数
成为“funnyworld”

self.myFunction = function (arg1, arg2, arg3) {
      // this === $data
      // arg1 === 'funnyworld'
      // arg2 === $data
      // arg3 === event
}

参见情况A:

$root.myFunction.bind($data)
$root.myFunction.bind($data, 'funnyworld')
将导致
myFunction
中的
this
成为当前视图模型(
$data
)。通常的参数也将通过Knockout传递,因此您的参数实际上是:

self.myFunction = function (arg1, arg2) {
      // this === $data
      // arg1 === $data
      // arg2 === event
}
情况B:

$root.myFunction.bind($data)
$root.myFunction.bind($data, 'funnyworld')
还会导致
myFunction
中的
this
成为当前视图模型(
$data
),但也会使第一个参数
成为“funnyworld”

self.myFunction = function (arg1, arg2, arg3) {
      // this === $data
      // arg1 === 'funnyworld'
      // arg2 === $data
      // arg3 === event
}

请参见

我使用语法$root.myFunction.bind everywhere,因此另一个答案更接近我需要的,我测试了你的代码,它也可以工作,谢谢我使用语法$root.myFunction.bind everywhere,因此另一个答案更接近我需要的,我测试了你的代码,它也可以工作,谢谢