开发者

Call overridden method in Dojo

In dojo, one cannot call a overridden superclass method outside of the same method in the derived class (for which 开发者_运维知识库there is this.inherited(), other than that one can call using class_name.function_name.apply). This feature is no longer there because of some refactoring and dojo guys are not going to put it back because they are not convinced about a good enough case for this. Please read this mail thread for details. Isn't there a good enough case for this functionality? Why or why not?


I would think that there is a very valid use case for such behaviour.

Consider implementing a state pattern using javascript objects. You can simply do it by maintaining the member variables in the current object, and all the state specific functions in the prototype. Just keep changing the prototype to move to a different state.

Now, when you want to combine the state pattern with the template method pattern, you can simply call the state functions as super()(like how you can in python). This is important because the state functions may be hooks or abstract functions in the template method class. If they are the former, then you should be able to call the super-class versions of these methods irrespective of which super-class the current super-class is.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜