Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/actionscript-3/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Actionscript 3 确定是否使用super调用ActionScript方法_Actionscript 3_Super - Fatal编程技术网

Actionscript 3 确定是否使用super调用ActionScript方法

Actionscript 3 确定是否使用super调用ActionScript方法,actionscript-3,super,Actionscript 3,Super,我有一个方法,每次调用它时都会记录一条消息。我希望此日志消息指示是直接调用该方法还是在子类中使用super调用该方法 class-DoerOfWork{ 公共函数doWork():void{ var calledWithSuper:布尔值; 调用WithSuper=???; 跟踪(“称为“+(称为WithSuper?”(带super)。”:“); } } 类SlowerDoerOfWork扩展了DoerOfWork{ 公共重写函数doWork():void{ 对于(变量i:Number=0;i

我有一个方法,每次调用它时都会记录一条消息。我希望此日志消息指示是直接调用该方法还是在子类中使用
super
调用该方法

class-DoerOfWork{
公共函数doWork():void{
var calledWithSuper:布尔值;
调用WithSuper=???;
跟踪(“称为“+(称为WithSuper?”(带super)。”:“);
}
}
类SlowerDoerOfWork扩展了DoerOfWork{
公共重写函数doWork():void{
对于(变量i:Number=0;i<321684;i++){
//等一下
}
super.doWork();
}
}
我希望通过将
this.doWork
DoerOfWork.prototype.doWork
进行比较,可以确定
this
类是否覆盖了
doork
的实现

class DoerOfWork {
    public function doWork():void {
        var calledWithSuper:Boolean; 

        calledWithSuper = this.doWork == arguments.callee;

        trace("doWork called" + (calledWithSuper ? " (with super)." : "."));
    }
}
不幸的是,这是不可能的。在ActionScript中的任何地方都无法访问未绑定方法(规范列出了两种类型的函数:函数闭包和绑定方法)。
MethodClosure
上的实例上甚至没有任何属性可以识别两个是否是同一方法的绑定副本


如何检查某个方法是否已被重写或使用任何其他方法来确定当前正在执行的ActionScript方法是使用
super
调用的还是直接调用的?

您可以将当前正在执行的函数的引用作为
参数。被调用方
。从方法中,这将是
DoerOfWork().doWork()
this
MethodClosure
。如果未覆盖
doWork()
,则此值将等于
this.doWork

class DoerOfWork {
    public function doWork():void {
        var calledWithSuper:Boolean; 

        calledWithSuper = this.doWork == arguments.callee;

        trace("doWork called" + (calledWithSuper ? " (with super)." : "."));
    }
}

如果在非严格模式下运行,显然这将禁用当前函数的参数计数检查。(我自己还没有检查过,我甚至不知道如何在IntelliJ中禁用严格模式。)

如果您愿意使用
flash.utils.describeType()
,它包含我们需要的信息:


XML中每个
declaredBy
属性使用与
flash.utils.getQualifiedClassName
相同的格式,我们可以比较这些属性以确定是否覆盖了实现

class DoerOfWork {
    public function doWork():void {
        var calledWithSuper:Boolean; 

        var currentImplementationFrom:String
          = flash.utils.describeType(this).method.(@name=="doWork").@declaredBy;
        var thisImplementationFrom:String
          = flash.utils.getQualifiedClassName(DoerOfWork);

        calledWithSuper = currentImplementationFrom != thisImplementationFrom;

        trace("doWork called" + (calledWithSuper ? " (with super)." : "."));
    }
}