Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Access to parent(super) methods within component #344

Open
igor-tomov opened this issue Jul 31, 2014 · 1 comment
Open

Access to parent(super) methods within component #344

igor-tomov opened this issue Jul 31, 2014 · 1 comment

Comments

@igor-tomov
Copy link

Hi,

I decide to implement my custom components behavior via components.addType(type, def). In fact, as I understood, an object, which I'm passing to this method will be prototype for all components with appropriate type. But there I faced with issue of getting access to prototype methods(super), which I override in my concrete component (in my case it concerns to initialize method).

For example, we have new component type:

components.addType( "custom", {
    initialize: function( opts ){
        // some basic initialization
    }
    ......
})

and then, I want to call it within of overridden method:

define({
    type: "custom",

    initialize: function( opts){
        // like this
        this.__super__.initialize.call( this, opts );

        // or maybe like in "Base2" or "jQuery UI Widget factory"
        this._super( opts );
    }
})

Of course, JavaScript doesn't support such mechanism for inheritance, but many famous libraries such as Base2 of Dean Edwards and jQuery UI Widget factory implemented workaround for accessing to super methods. In Component.extend(), which is used for component inheritance, I didn't find such mechanism.

Actually, I have found one way, but it looks awful:

this.constructor.__ super__.constructor.__super__[ "propertyName" ];

Though, we can register callback via components.before() for this situation. But, I think, it's not really good idea, because this is more common approach and used for all loaded components.

So. Is there some convenient way to resolve it?
Sorry for my bad English :( I hope, I described it correctly.

@josephspens
Copy link

Maybe we try something like Backbone's initialize. Initialize is a noop, a function the developer can write themselves for any custom initialize functionality, and Backbone will use constructor under the hood. So a private method paired with a public, overridable noop for the developer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants