[英]AS3 Class Function Scope
If I have 2 classes and the first extends the second, how can the second class call a static function from the first? 如果我有2个类,而第一个类扩展了第二个类,那么第二个类如何从第一个类调用静态函数?
package p1 {
class a {
static function a1() {
//do soemthing
}
}
class b extends a {
static function b1() {
//do something else
}
}
}
a.a1(); // this works
b.a1(); // this doesn't work
b.b1(); //this works
When "B extends A" - this actually is not the same as "class B has all methods and properties of A". 当“ B扩展A”时-实际上与“类B具有A的所有方法和属性”不同。 Not class, but object of class B implements all properties and methods, defined in class A. When you call a static method or property - you deal with classes but not objects (it looks very similar to namespaces usage).
不是类,而是类B的对象实现了类A中定义的所有属性和方法。调用静态方法或属性时,您处理的是类而不是对象(它与名称空间的用法非常相似)。
ADDED: The only way solve your task is to override a1(args) in class B and to call super.a1(args) inside... 1 string of code. 添加:解决您任务的唯一方法是重写类B中的a1(args)并在... 1个代码字符串内调用super.a1(args)。 But it seems to me, that you have a software architect problem if it's not possible to avoid such kind of usage.
但是在我看来,如果无法避免这种使用,您就会遇到软件架构师问题。
Use super to call the parent method. 使用super调用父方法。
super.b1();
EDIT: Ok, looking at what you wrote, I think you need to set the scope of a1 to be public or protected. 编辑:好的,看看您写的内容,我认为您需要将a1的范围设置为公共或受保护。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.