Skip to content

Instantly share code, notes, and snippets.

@chuck0523
Created August 8, 2015 05:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chuck0523/55b428ced07482fcae86 to your computer and use it in GitHub Desktop.
Save chuck0523/55b428ced07482fcae86 to your computer and use it in GitHub Desktop.
var myObj = {
value : 0,
increment : function(inc) {
this.value += typeof inc === 'number' ? inc : 1;
}
};
myObj.increment();
console.log(myObj.value); // 1
myObj.increment(2);
console.log(myObj.value); // 3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment