内部javascript清除功能

Jas*_*son 2 javascript

我有两个用于复制数据对象的javascript对象.它们通过onclick事件填充,我想在保存事件后清除它们.

例如,

var currentStrategy = {
  id : "",
  label : "",
  dueDate : "",
  comments = [],

  save : saveStrategyHandler,
  clear : function() {
    //how do I clear the fields above in here?
  }
}
Run Code Online (Sandbox Code Playgroud)

我试过了

function(){
  id = "";
  label = "";
  dueDate = "";
  comments = [];
}
Run Code Online (Sandbox Code Playgroud)

function(){
  currentStrategy = {};
}
Run Code Online (Sandbox Code Playgroud)

但都没有工作.

sab*_*bof 6

使用以下内容.实例属性需要一个this.

var currentStrategy = {
  id : "",
  label : "",
  dueDate : "",
  comments = [],

  save : saveStrategyHandler,
  clear : function() {
    this.id = "";
    this.label = "";
    this.dueDate = "";
    this.comments = [];
  }
}
Run Code Online (Sandbox Code Playgroud)