Skip to content

Resolving name conflicts by renaming is broken #3

Description

@fresheneesz

Hey, this is very interesting to me, but I'm noticing a couple related flaws.

  1. Resolving a name conflict by renaming is broken. If your trait needs to access a property through 'this', the renaming will cause incorrect access. Consider this:
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
  1. Similar problems exist for other forms of resolution that are provided

  2. 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:

  • is there a difference between resolution option 2 and 3 (from here http://howtonode.org/traitsjs )? Can't you always get the same result as overriding by selectively excluding?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions