Created
September 11, 2019 15:48
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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