2

I have two javascript objects that are used to replicate data objects. They are filled in via onclick events, and I want to clear them out after a save event.

For example,

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

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

I've tried

function(){
  id = "";
  label = "";
  dueDate = "";
  comments = [];
}

and

function(){
  currentStrategy = {};
}

but neither work.

Jason
  • 11,263
  • 21
  • 87
  • 181

1 Answers1

6

Use the following. Instance properties need a this.

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

  save : saveStrategyHandler,
  clear : function() {
    this.id = "";
    this.label = "";
    this.dueDate = "";
    this.comments = [];
  }
}
sabof
  • 8,062
  • 4
  • 28
  • 52