Skip to content

Instantly share code, notes, and snippets.

@NicholasKuchiniski
Created September 11, 2019 15:48
Show Gist options
  • Save NicholasKuchiniski/00de17760eb4481b9f9ee1a2436a6d47 to your computer and use it in GitHub Desktop.
Save NicholasKuchiniski/00de17760eb4481b9f9ee1a2436a6d47 to your computer and use it in GitHub Desktop.
Increment value from a object using object.assign and get the new value at the next get of the object
function setup () {
return {
obj: { val: 1 },
increment() { return Object.assign(this.obj, { val: this.obj.val + 1 })},
}
}
const object = setup();
console.log(object.obj.val);
object.increment();
object.increment();
object.increment();
object.increment();
object.increment();
object.increment();
object.increment();
object.increment();
object.increment();
object.increment();
console.log(object.obj.val);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment