Hi, I have a big JS class and wanted to clean it by grouping same
functions. What I did was something like that :

Parent = new Class({
    initialize: function(options) {
        console.log('Initialized');

        this.Child.a();
    },

    a: function() {
        console.log('Function a::Parent called');
    },

    b: function() {
        console.log('Function b::Parent called');
    },

    Child: {
        a: function() {
            console.log('Function a::Child called');
            this.b();
        }
    }
});

window.addEvent('domready', function() {
    new Mother();
});

This will return :
Initialized
Function a::Child called

and Error, b undefined, because this refers to this.Child while in
this.Child.a().

is there any other mean to have this refering to Parent while in
Parent.Child, without calling all the functions with :
this.Child.a.apply(this, {}); ?

Regards, Olivier.

Reply via email to