stampit-org / stampit

OOP is better with stamps: Composable object factories.
https://stampit.js.org
MIT License
3.02k stars 102 forks source link

Simplest example displays the wrong output. #273

Closed kurtpeters closed 7 years ago

kurtpeters commented 7 years ago

I noticed the last two commented outputs from the "simplest example" are incorrect. Since the initializer is destructuring the argument

const MyStamp = stampit()       // create new empty stamp
.props({                        // add properties to your future objects
  myProp: 'default value'
})
.methods({                      // add methods to your future objects
  getMyProp() {
    return this.myProp;
  }
})
.init(function ({value}) {      // add initializers to your future objects
  this.myProp = value || this.myProp;
})

should the following

console.log(MyStamp('new value'));             // { myProp: 'new value' }
console.log(MyStamp('new value').getMyProp()); // new value

be documented to reflect to the destructuring from the initializer?

console.log(MyStamp({value: 'new value'}));             // { myProp: 'new value' }
console.log(MyStamp({value: 'new value'}).getMyProp()); // new value
danielkcz commented 7 years ago

Good catch, thanks! Would you mind creating the PR?

kurtpeters commented 7 years ago

No problem! Here's the PR - https://github.com/stampit-org/stampit/pull/274