当我们将一个函数订阅多个属性时,有什么方法可以找到哪个属性正在调用订阅的函数?
代码示例。
var self = this;
$(document).ready(function(){
var myViewModel =
{
FirstName : ko.observable("Bert"),
LastName : ko.observable("pual")
};
myViewModel.FirstName.subscribe(self.notifyChange);
myViewModel.LastName.subscribe(self.notifyChange);
ko.applyBindings(myViewModel);
});
notifyChange = function ( newValue ) {// want to find which property(FirstName/LastName) is calling the function }
HTML
<body>
Enter your name:
<input id="source" data-bind="value: FirstName" />
<input id="Text1" data-bind="value: LastName" />
在这里,我为 FirstName 和 LastName 订阅了“notifyChange”功能。如果任何一个值发生更改,它将调用 notifyChange 函数,我想知道哪些属性更改会调用 notifyChange 函数?