Created
April 10, 2014 15:25
-
-
Save jeremybuis/10393830 to your computer and use it in GitHub Desktop.
An implementation of the extend function for object mixin
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
// Taken from | |
// http://raganwald.com/2014/04/10/mixins-forwarding-delegation.html | |
(function(window) { | |
var __slice = [].slice; | |
function extend () { | |
var consumer = arguments[0], | |
providers = __slice.call(arguments, 1), | |
key, | |
i, | |
provider, | |
except; | |
for (i = 0; i < providers.length; ++i) { | |
provider = providers[i]; | |
except = provider['except'] || []; | |
except.push('except'); | |
for (key in provider) { | |
if (except.indexOf(key) < 0 && provider.hasOwnProperty(key)) { | |
consumer[key] = provider[key]; | |
}; | |
}; | |
}; | |
return consumer; | |
}; | |
window.extend = extend; | |
})(window); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment