Created
August 5, 2014 12:43
-
-
Save jeroenransijn/c01873bb96b1b2469181 to your computer and use it in GitHub Desktop.
mix().in()
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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