Skip to content

Instantly share code, notes, and snippets.

@jeroenransijn
Created August 5, 2014 12:43
Show Gist options
  • Save jeroenransijn/c01873bb96b1b2469181 to your computer and use it in GitHub Desktop.
Save jeroenransijn/c01873bb96b1b2469181 to your computer and use it in GitHub Desktop.
mix().in()
/**
* Author: Jeroen Ransijn
* Date: August 5 2014
* Pass functions as arguments
*/
function mix () {
var args = Array.prototype.slice.call(arguments), argsLength = args.length;
return {
in: function (fn) {
for (var i = 0; i < argsLength; i++) {
args[i].call(fn);
}
return fn;
}
};
}
// Example A
var Events = function () {
this.on = function () { return 'on'; };
this.off = function () { return 'off'; };
this.trigger = function () { return 'trigger'; };
};
var View = function () {};
mix(Events).in(View);
View.on(); // => 'on
// Example B
var Templating = function () {
this.template = function () { return 'Love to hate the "smart" prefix'; };
};
var SmartMix = mix(Events, Templating);
var SmartView = function () {};
SmartMix.in(SmartView);
SmartView.template(); // => 'Love to hate the "smart" prefix'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment