Hi guys,
I sometimes run into this doubt when I have to use someone else classes
or API. Let's see this example:
/* API or Class: */
var SomeOneElseClass = function (args) {/*...*/};
SomeOneElseClass.prototype = {
doSomething : function () {/*...*/},
doSomethingElse : function () {/*...*/}
}
/**************************************/
/* Wrapping: */
var MyClass = function (args) {
this.__someOneElseClass = new SomeOneElseClass(args);
// ...
};
MyClass.prototype.doEverything = function () {
this.__someOneElseClass.doSomething();
this.__someOneElseClass.doSomethingElse();
}
/**************************************/
/* Extending: */
var MyClass = extend(SomeOneElseClass, {
constructor : function (args) {
MyClass.superclass.constructor.apply(this, args);
// ...
},
doEverything : function () {
this.doSomething();
this.doSomethingElse();
}
});
/**************************************/
Could anyone tell me pros and cons of using one or the other ?
Thanks.
--
To view archived discussions from the original JSMentors Mailman list:
http://www.mail-archive.com/[email protected]/
To search via a non-Google archive, visit here:
http://www.mail-archive.com/[email protected]/
To unsubscribe from this group, send email to
[email protected]