Skip to content
Adam McArthur edited this page Jun 24, 2014 · 1 revision

Instances can be reset, or cleared.

  • Reset: .reset(); - The Instance reverts back to it's default values.
  • Cleared: .clear(); - The Instance clears everything including default values.

For the purpose of this guide, we'll pretend we already have an instance stored in a variable called Comment. It has some parameters, too:

var Comment = new Instance({
   defaults: {
      subscriber: false,
      mailing_list: false
   }
});

// Add some stuff
Comment.add({
   name: "Adam",
   body: "Instance is pretty cool.",
   reply_to: "Favourite javascripts?"
});

// What does our Comment look like
console.log(Comment.get());
// => { subscriber: false, mailing_list: false, name: "Adam", body: "Instance is pretty cool.", reply_to: "Favourtie javascripts?" }

Now check out the effect each of the methods has on the Comment Instance...

Comment.reset();

console.log(Comment.get());
// => { subscriber: false, mailing_list: false }
Comment.clear();

console.log(Comment.get());
// => {}

Want to contribute to instance.js? Find out how.

Clone this wiki locally