component / model

Minimalistic extensible data models
122 stars 40 forks source link

suggestion: call plugins with .call #55

Closed yields closed 10 years ago

yields commented 10 years ago

https://github.com/component/model/blob/master/lib/static.js#L97

so instead of fn(this) do fn.call(fn, this).

IMHO this gives you a lot of flexibility when building plugins, for example you could build plugins like so:

model.use(new Plugin())

function Plugin(){}
Plugin.prototype.call = function(model){};

also you can configure plugins in a nice-ish way

plugin = Plugin()
  .set('foo', 'baz')
  .set('baz', 'foo');

User = model('User').use(plugin);
yields commented 10 years ago

nvm