Hey all,
How do I transfer properties, for example pushing to an array my
receiverClass, while it is augmented by a 'givingClass' under Addy Osmani's
augmentation
approach
<http://addyosmani.com/resources/essentialjsdesignpatterns/book/#mixinpatternjavascript>
?
I seem only able to effect the transfer of prototype functions, but can't
monkey around with other property members or set properties on the
receivingClass :(
// Extend an existing object with a method from another
function augment( receivingClass, givingClass ) {
// only provide certain methods
if ( arguments[2] ) {
for ( var i = 2, len = arguments.length; i < len; i++ ) {
receivingClass.prototype[arguments[i]] =
givingClass.prototype[arguments[i]];
}
}
// provide all methods
else {
for ( var methodName in givingClass.prototype ) {
// check to make sure the receiving class doesn't
// have a method of the same name as the one currently
// being processed
if ( !Object.hasOwnProperty.call(receivingClass.prototype,
methodName) ) {
receivingClass.prototype[methodName] =
givingClass.prototype[methodName];
}
// Alternatively (check prototype chain as well):
// if ( !receivingClass.prototype[methodName] ) {
// receivingClass.prototype[methodName] =
givingClass.prototype[methodName];
// }
}
}
}
--
Job board: http://jobs.nodejs.org/
New group rules:
https://gist.github.com/othiym23/9886289#file-moderation-policy-md
Old group rules:
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
---
You received this message because you are subscribed to the Google Groups
"nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/nodejs/92c06024-365d-4e4d-bd8d-3b2ee5d7581a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.