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.

1
  • Assign to the properties of your object, not to some variables. Commented Jul 28, 2013 at 17:34

1 Answer 1

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 = [];
  }
}
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.