I change your code to do what you actually are communicating.
var Bar = new Class({
Extends : Foo, // added this line
options: {
fruits: {
apple: 'green',
lemon: 'yellow'
},
favoriteNumber: 12,
favoriteColor: 'blue'
},
initialize: function(options){
this.parent(options); //sets options
console.log(this.options); // look at the whole option object
}
});
This yields:
{
fruits: {
apple: 'green',
lemon: 'yellow',
orange : 'orange'
},
favoriteNumber: 12,
favoriteColor: 'blue'
}
Looks good to me.
On Wed, Sep 17, 2008 at 9:01 PM, keif <[EMAIL PROTECTED]> wrote:
>
>
> Well, if it did that, it would be working.
>
> Unfortunately, when I say:
> var Foo = new Class({
> Implements: Options,
> options: {
> fruits: {
> apple: 'red',
> orange: 'orange'
> },
> favoriteNumber: 10
> },
> initialize: function(options){
> this.setOptions(options);
> }
> });
>
> var Bar = new Class({
> options: {
> fruits: {
> apple: 'green',
> lemon: 'yellow'
> },
> favoriteNumber: 12,
> favoriteColor: 'blue'
> },
> initialize: function(options){
> this.parent(options); //sets options
> console.log(this.options.fruits.apple); //logs 'green'
> console.log(this.options.fruits.orange); //logs null
> }
> });
>
>
>
> anutron wrote:
> >
> > When you extend a class, the options are blended together. Any options
> > that overlap will be overwritten:
> >
> > var Foo = new Class({
> > Implements: Options,
> > options: {
> > fruits: {
> > apple: 'red',
> > orange: 'orange'
> > },
> > favoriteNumber: 10
> > },
> > initialize: function(options){
> > this.setOptions(options);
> > }
> > });
> >
> > var Bar = new Class({
> > options: {
> > fruits: {
> > apple: 'green',
> > lemon: 'yellow'
> > },
> > favoriteNumber: 12,
> > favoriteColor: 'blue'
> > },
> > initialize: function(opitions){
> > this.parent(options); //sets options
> > console.log(this.options.fruits.apple); //logs 'green'
> > console.log(this.options.favoriteNumber); //logs 12
> > console.log(this.options.favoriteColor); //logs 'blue'
> > }
> > });
> >
> >
> > keif wrote:
> >>
> >> So the extended class options override the original class options.
> >>
> >> I have to pass the class options into the first class, then into the
> >> second class as well - I have a feeling this isn't by design, so odds
> are
> >> I'm doing something wrong when I do this.parent();
> >>
> >>
> >> keif wrote:
> >>>
> >>> I'm extending noobslide:
> >>> http://www.efectorelativo.net/laboratory/noobSlide/
> >>>
> >>> but when I extend the class, it overwrites the original options.
> >>>
> >>> var mooSlideResource = new Class({
> >>> Extends: mooSlide,
> >>>
> >>> options: {
> >>> 'captionsContainer': null,
> >>> 'description': false,
> >>> 'hoverButtons': null,
> >>> 'hoverActionsFx': {
> >>> 'duration': 250,
> >>> 'transition': Fx.Transitions.linear
> >>> },
> >>> 'hoverOffset': 25
> >>> },
> >>>
> >>> initialize: function(options){
> >>> console.debug('resource slide', options);
> >>>
> >>> // Include parent options
> >>> this.parent(options);
> >>> }
> >>>
> >>> It then overwrites the original options I dump with a
> >>> console.debug(options);
> >>>
> >>> Anyone have any insight to this?
> >>>
> >>>
> >>
> >>
> >
> >
>
> --
> View this message in context:
> http://n2.nabble.com/Extending-a-class.-tp1095871p1097025.html
> Sent from the MooTools Users mailing list archive at Nabble.com.
>
>