简体   繁体   中英

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM