What are the key differences between JavaScript and ActionScript 3?

后端 未结 7 2044
孤城傲影
孤城傲影 2020-12-01 05:39

I know both languages are from the same ECMA-262 standard. It seems that the two are becoming very similar with JavaScript adding event listeners for core Object instances t

7条回答
  •  北荒
    北荒 (楼主)
    2020-12-01 05:43

    The key differences are that ActionScript 3 supports both class-based inheritance and prototypal inheritance, enforces namespace bindings between class names and file names, and does not support some global JavaScript methods such as eval. Fortunately, you can do several things to bridge the gap.

    You can globally set the namespace using ES for ECMAScript or AS3 for ActionScript 3:

    use namespace ES;
    use namespace AS3; 
    

    If you are using the AS3 namespace, any method override must use the AS3 namespace and the override attribute.

    If you are not using the AS3 namespace, you can use the prototype methods and propertyIsEnumerable.

    You can selectively use the AS3 namespace version of a property or method in a dynamic function:

    var nums:Array = new Array(1, 2, 3); 
    nums.AS3::pop(); 
    trace(nums); // output: 1,2
    

    To turn off class based inheritance, you can also use the following compiler options: compc -as3=false -strict=false -es=true

    import *
    class foo
      {
      dynamic function foo() 
        {
    
        }
      }
    

    If you do not use the AS3 namespace, an instance of a core class inherits the properties and methods defined on the prototype object.

    If you decide to use the AS3 namespace, an instance of a core class inherits the properties and methods defined in the class definition.

    Here is a common features between ECMAScript-4 and ECMAScript-2017 or later:

    Feature 		 ES4/ES6+ 	ES4 Only                    
    Rest parameter 		 ☑ 
    Destructuring 		 ☑
    ByteArrays 		 ☑
    Class 		 	 ☑  
    Interface 		 		 ☑
    Static fields 		 		 ☑
    Parameter default 	 ☑
    Rest Parameters 	 ☑
    Bound methods 		 		 ☑
    dynamic this value 			 ☑
    multiple catch clauses 			 ☑
    short-circuit-and (&&=) 		 ☑
    short-circuit-or (||=) 			 ☑
    Type Annotations 			 ☑
    

    References

    • Simulating AS3 language features in JavaScript using AMD and ES5

    • JavaScript 2 Draft

    • ECMAScript 4th Edition[proposed]:Predefined Types and Objects

    • The New Browser War

    • ECMAScript 1-on-1

    • The Trouble with JavaScript: JavaScript has no Class

    • What's New in ECMAScript-4

    • David Flanagan on JavaScript 2

    • JavaScript 2 and the Future of the Web

    • Writing Classes

    • Faster byte array operations with ASC2

    • Managing event listeners

提交回复
热议问题