EDIT: я случайно использовал MooTools typeOf () , не задумываясь. Исправлено.
Вот что я придумала. Я признаю, что это излишне для большинства ситуаций, но синтаксис на стороне шаблона немного чище:
Просмотр модели:
var ViewModel = new function() {
this.call = function(functions,args) {
if (!(functions instanceof Array))
functions = [functions];
if (!(args instanceof Array))
args = [args];
return function() {
for (var i = 0, l = functions.length; i < l; i++) {
functions[i].apply(this,args);
}
}
}
this.testValue=ko.observable('Click me!');
this.click1 = function(foo) {
this.testValue('click1 ' + foo);
alert(1);
}
this.click2 = function(foo) {
this.testValue('click2 ' + foo);
alert(2);
}
}
и шаблон
<span data-bind="click:call([click1,click2],['Test value'])">Test span</span>