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

this.__base contains undefined in next tick #17

Open
j0tunn opened this issue Nov 18, 2014 · 19 comments
Open

this.__base contains undefined in next tick #17

j0tunn opened this issue Nov 18, 2014 · 19 comments

Comments

@j0tunn
Copy link

j0tunn commented Nov 18, 2014

It would be nice to be able to call same method from parent class from next tick. Something like:

var C = inherit(B, {
    someMethod: function() {
        return doSomethingAndReturnPromise()
            .then(this.__parent.someMethod.bind(this));
    }
});

It would be more readable then workaround a la "save this.__base to variable and then call it"

@j0tunn
Copy link
Author

j0tunn commented Nov 18, 2014

@arikon

@dfilatov
Copy link
Owner

I'm not sure that I understand what you mean, but this code works as expected:

var A = inherit({
    m1 : function(res) {
        return vow.resolve('A' + res);
    }
});

var B = inherit(A, {
    m1 : function() {
        return vow.resolve('B').then(this.__base, this);
    }
});

new B().m1().then(function(res) {
    console.log(res); // AB
});

@j0tunn
Copy link
Author

j0tunn commented Nov 18, 2014

And what about

var B = inherit(A, {
    m1 : function() {
        return vow.resolve('B').then(function() {
             return this.__base();
        }, this);
    }
});

?

@dfilatov
Copy link
Owner

It's not possible

@j0tunn
Copy link
Author

j0tunn commented Nov 18, 2014

Thats the point

@dfilatov
Copy link
Owner

this.__base exists only while method is being called. Because after that you're able to call another method with its own this.__base.

@j0tunn
Copy link
Author

j0tunn commented Nov 18, 2014

Блин, я это и из кода понял :) Речь как раз о том, что это неудобно.
Хочется что-то вроде такого из плюсов:

class A {
    virtual void someMethod() {
        // do something
    }
};

class B : public A {
    void someMethod() override {
        // do something else
        A::someMethod();
    }
};

@dfilatov
Copy link
Owner

Ну можешь так:

this.__self.__parent.prototype.someMethod.call(this);

Не уверен, что это удобнее )

@j0tunn
Copy link
Author

j0tunn commented Nov 18, 2014

this.__self.prototype.someMethod()

это по идее вызовет метод этого же класса, т.е. этот же метод

@dfilatov
Copy link
Owner

я поправил

@j0tunn
Copy link
Author

j0tunn commented Nov 18, 2014

this.__self.__parent.prototype.someMethod() ?

@dfilatov
Copy link
Owner

да

@j0tunn
Copy link
Author

j0tunn commented Nov 18, 2014

Вот было бы ништяк __self.__parent.prototype заменить на какое-нибудь одно имя, типа this.__parentPtp.someMethod()

@j0tunn
Copy link
Author

j0tunn commented Nov 18, 2014

ну или вообще this.__parent.someMethod()

@dfilatov
Copy link
Owner

ок, скорее всего добавлю второй вариант

@dfilatov dfilatov reopened this Nov 19, 2014
@qfox
Copy link

qfox commented Jan 22, 2016

Is this still actual? Looks like a good idea.

@dfilatov
Copy link
Owner

Я еще раз подумал — оно же не будет так this.__parent.someMethod() работать, только так — this.__parent.someMethod.call(this). А это уже как-то сомнительно.

@qfox
Copy link

qfox commented Jan 25, 2016

Может динамически как-то при доступе к __parent магию делать?

@dfilatov
Copy link
Owner

Если у тебя есть идеи как (у меня нет), то я готов их обсудить.

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

3 participants