如果我在课堂上声明这个
class AlertConfigViewModel {
DeleteAlert = function (item) {
if (item) {
if (confirm('Are you sure you wish to delete this item?')) {
this.Alerts.remove(item);
}
}
else {
alert("something is wrong");
}
};
}
结果是这样的:
var AlertConfigViewModel = (function () {
function AlertConfigViewModel(json) {
this.DeleteAlert = function (item) {
if(item) {
if(confirm('Are you sure you wish to delete this item?')) {
this.Alerts.remove(item);
}
} else {
alert("something is wrong");
}
};
}
}
如果我在 AlertConfigViewModel 的上下文之外调用 AlertConfigViewModel,那么“this”不是 AlertConfigViewModel,我认为它会因为它的内部函数 AlertConfigViewModel(