Created
March 25, 2010 14:58
-
-
Save rhyolight/343636 to your computer and use it in GitHub Desktop.
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 mixin(from, to) { | |
var property; | |
for (property in from) { | |
if (!to.hasOwnProperty(property)) { | |
to[property] = from[property]; | |
} | |
} | |
return to; | |
} |
I don't understand how this helps the mixin? Are you talking about calling the mixin method via apply like this:
function mixin(from) {
var property;
for (property in from) {
if (!this.hasOwnProperty(property)) {
this[property] = from[property];
}
}
}
mixin.call(myInstance, superInstance);
(using https://developer.mozilla.org/En/Core_JavaScript_1.5_Reference/Objects/Function/Call instead of apply so I don't have to wrap arg in [])
Wow, so I tried the idea out:
This is all relating back to http://rhyolight.posterous.com/javascript-constructor-performance (in case anyone reading was wondering)
Re: apply
You're right, it's more appropriate for the classic prototypal inhertance.
Re: performance. Woohoo, good deal! (Though I'm glad you simplified things a bit for the blog follow-up. I started getting lost in all those permutations.)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The
apply
function might be a better option altogether: https://developer.mozilla.org/En/Core_JavaScript_1.5_Reference/Objects/Function/Apply