1

Say just for fun I want to override Array and redefine map:

public dynamic class MagicArray extends Array {
  public override function map(f:Function, thisObject:* = null):Array {
    var result:Array = [];

    for (var i:int = 0; i < this.length; i++) {
      result.push(f(this[i]));
    }

    return result;
  }
}

We get this error: Method marked override must override another method.

Huh?

So I stripped the override keyword and tried again. Now, everything compiles fine. But if we try to use it:

var a:MagicArray = new MagicArray([1,2,3]);
a.map(function(x) { return x + 1; }); 

We get the following error:

Error: Ambiguous reference to map.

So what's going on here? How can I override map?

4

1 回答 1

1

您是否使扩展成为动态的,您是否使用命名空间,请参见此处http://help.adobe.com/en_US/as3/dev/WS5b3ccc516d4fbf351e63e3d118a9b8d829-7fde.html

于 2012-07-03T21:25:55.307 回答