ftlabs / fruitmachine

View rendering engine
MIT License
247 stars 18 forks source link

`options` object #46

Open wilsonpage opened 11 years ago

wilsonpage commented 11 years ago

As a module author I would like to be able to accept certain options that override default behaviour/characteristics. Currently this can be done manually by throwing keys onto the object passed into the constructor, and retrieving them inside the initialize callback.

var apple = new Apple({
  model: { foo: 'bar' },
  children: {},
  random: 'option'
});

later retrieved inside the module:

initialize: function(config) {
  var options = config.options || {};
  var random = options.random;
}

This is a little dodgy as this space should be reserved for FruitMachine configuration only. It is not clear to see what is an option specific to this module and what is FruitMachine configuration. I suggest the following:

var apple = new Apple({
  module: { foo: 'bar' },
  children: {},
  options: {
    random: 'option'
  }
});

later retrieved inside the module:

initialize: function(options, config) {
  var random = options.random;
}
matthew-andrews commented 11 years ago

This feels like it could be a mixin plugin helper...