本文介绍了如何在javascript/ajax中获取父类的派生类列表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个javascript类(childA childB),每个都继承自另一个javascript类(Parent).父级包含一个myMethod 函数,该函数被子级覆盖.所有这些类也位于不同的文件中,这些文件已加载到页面上.

我想做的是调用每个派生类的myMethod.我正试图使我的问题非常简短和切题.发生了很多事情,但是我要弄清我的实际问题是什么.

我的问题:
1.我想做的是动态获取从Parent继承的已注册类的列表.我想调用每个派生类的myMethod.
2.从性能的角度来看这会是一个不好的做法吗?

I have two javascript classes (childA and childB), each inheriting from another javascript class (Parent). The parent contains a myMethod function which is overridden by the child classes. All these classes are in different files as well which are loaded on the page.

What I''m trying to do is invoke each of the derived class''s myMethod. I''m trying to keep my question very brief and to the point. There are a bunch of things going on, but I''m zeroing down on what my actual question is.

My questions:
1. What I''d like to do is get a list of registered classes dynamically which inherit from Parent. I would like to invoke myMethod of each of these derived classes.
2. Would this be a bad practice from a performance perspective?

...
Parent.prototype.myMethod  = function(methodName)
{
}



谢谢!



Thanks!

推荐答案


这篇关于如何在javascript/ajax中获取父类的派生类列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-17 09:19