内部javascript清除函数

内部javascript清除函数,javascript,Javascript,我有两个用于复制数据对象的javascript对象。它们是通过onclick事件填写的,我想在保存事件后清除它们 比如说, var currentStrategy = { id : "", label : "", dueDate : "", comments = [], save : saveStrategyHandler, clear : function() { //how do I clear the fields above in here? } }

我有两个用于复制数据对象的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 = [];
}


但这两种方法都不起作用。

使用以下方法。实例属性需要一个
this

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

  save : saveStrategyHandler,
  clear : function() {
    this.id = "";
    this.label = "";
    this.dueDate = "";
    this.comments = [];
  }
}
指定给对象的属性,而不是某些变量。
var currentStrategy = {
  id : "",
  label : "",
  dueDate : "",
  comments = [],

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