Hey, this is very interesting to me, but I'm noticing a couple related flaws.
var Holder = Trait({
can: 'beans',
inventory: function() {
return this.can // number of steps to build
}
})
var Doer = Trait({
can: function(action) {
if(action === 'grow')
return true
else
return false
},
grow: function() {
if(this.can('grow'))
console.log("Growing...")
}
})
var Person = Trait.compose(Holder, Trait.resolve({can: "canDo"},Doer))
var guy = Trait.create({}, Person);
console.log(guy.inventory())
guy.grow() // throws exception
Hey, this is very interesting to me, but I'm noticing a couple related flaws.
Similar problems exist for other forms of resolution that are provided
Maybe I'm just not understanding how to use Traits, but I can't find a way to specify a required property that isn't read only (ie can be manipulated by trait methods)
Question: