Mel*_*lon 3 javascript model-view-controller javascript-events javascript-framework
我在这里看到了一个javascript MVC文章,模型定义为:
var ListModel = function (items) {
this._items = items;
this._selectedIndex = -1;
this.itemAdded = new Event(this);
this.itemRemoved = new Event(this);
this.selectedIndexChanged = new Event(this);
};
ListModel.prototype = {
getItems : function () {
return [].concat(this._items);
},
addItem : function (item) {
this._items.push(item);
this.itemAdded.notify({item: item});
},
removeItemAt : function (index) {
var item = this._items[index];
this._items.splice(index, 1);
this.itemRemoved.notify({item: item});
if (index == this._selectedIndex)
this.setSelectedIndex(-1);
},
getSelectedIndex : function () {
return this._selectedIndex;
},
setSelectedIndex : function (index) {
var previousIndex = this._selectedIndex;
this._selectedIndex = index;
this.selectedIndexChanged.notify({previous: previousIndex});
}
};
Run Code Online (Sandbox Code Playgroud)
问题1.在javascript中,下划线意味着什么?例如this._items
问题2.在模型中,它在哪里使用,如何使用以下内容:
this.itemAdded = new Event(this);
this.itemRemoved = new Event(this);
this.selectedIndexChanged = new Event(this);
Run Code Online (Sandbox Code Playgroud)