Created
September 15, 2012 23:35
-
-
Save loicfrering/3730354 to your computer and use it in GitHub Desktop.
Mixins for JavaScript
This file contains hidden or 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
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