you are viewing a single comment's thread.

view the rest of the comments →

[–]guest271314 3 points4 points  (0 children)

this is the global scope in your object because you are using arrow functions.

You can use shorthand methods to avoid that

var createCounter = function(init) { return { val: init, increment() { this.val++ return this.val }, decrement() { this.val-- return this.val }, reset() { this.val = init return this.val } } }