Skip to content

Instantly share code, notes, and snippets.

@loicfrering
Created September 15, 2012 23:35
Show Gist options
  • Save loicfrering/3730354 to your computer and use it in GitHub Desktop.
Save loicfrering/3730354 to your computer and use it in GitHub Desktop.
Mixins for JavaScript
Function.prototype.mixin = function() {
for (var i = 0; i < arguments.length; i++) {
mixin = arguments[i];
for (p in mixin) {
this.prototype[p] = mixin[p];
}
}
};
var Obj = function() {
};
Obj.mixin({
foo: function() {
console.log('bar');
}
});
var o = new Obj();
o.foo();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment