我有两个用于复制数据对象的javascript对象。它们通过onclick事件填充,我想在保存事件后清除它们。
例如,
var currentStrategy = {
id : "",
label : "",
dueDate : "",
comments = [],
save : saveStrategyHandler,
clear : function() {
//how do I clear the fields above in here?
}
}
我试过
function(){
id = "";
label = "";
dueDate = "";
comments = [];
}
和
function(){
currentStrategy = {};
}
但都不起作用。
答案 0 :(得分:6)
使用以下内容。实例属性需要this
。
var currentStrategy = {
id : "",
label : "",
dueDate : "",
comments = [],
save : saveStrategyHandler,
clear : function() {
this.id = "";
this.label = "";
this.dueDate = "";
this.comments = [];
}
}