diff --git a/README.md b/README.md index 536942b..d67dbe0 100644 --- a/README.md +++ b/README.md @@ -29,7 +29,9 @@ var n = Object.create(N) n.value = 3 -n.times(3) +n + .times(3) + .times(2) ``` @@ -69,10 +71,10 @@ var N = Actions({ ``` -Now to extend: +Now the extended: ```javascript -var ExtendedN = Actions(N, { +var ExtendedN = Actions({ times: [function(n){ console.log(this.value, 'times', n) @@ -88,13 +90,22 @@ And both objects can be used in the same way as before: ```javascript -var n = Object.create(ExtendedN) +// We mix the two, but either can be used as above... +var n = mix(N, ExtendedN) n.value = 3 -n.times(3) +n + .times(3) + .times(2) ``` +But now: +- `this` is returned automatically +- the _super_ method is called automatically +- both `N` and `ExtendedN` are reusable in different inheritance chains + without any extra work needed. + diff --git a/actions.js b/actions.js index 9d5ac83..0bd1d90 100755 --- a/actions.js +++ b/actions.js @@ -964,7 +964,7 @@ module.MetaActions = { // Mixin a set of actions into this... // - // NOTE: if 'all' is set them mixin all the actions available, + // NOTE: if 'all' is set then mixin all the actions available, // otherwise only mixin local actions... // NOTE: this will override existing own attributes. inlineMixin: function(from, all, descriptors, all_attr_types){ @@ -1303,6 +1303,25 @@ function Actions(a, b){ +/*********************************************************************/ + +var mix = +module.mix = +function(){ + var args = [].slice.call(arguments) + var res = {} + + var mixin = MetaActions.inlineMixin + + args.forEach(function(p){ + res = Object.create(mixin.call(res, p)) + }) + + return res +} + + + /*********************************************************************/ var test =