开发者

What are the key differences between JavaScript and ActionScript 3?

开发者 https://www.devze.com 2022-12-20 01:19 出处:网络
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 through metho

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 through methods like freeze and seal in EMCAScript-262 5th edition and such. I was wondering what the differences are?


First of all ActionScript 3 and JavaScript are both defined in ECMA-262 so they have a lot in common. Both languages feature prototype inheritance for instance. It is however not correct that ActionScript fully implements ES4.

ActionScript implements a couple of features that are not defined in ECMA-262 and some -- but definitely not all -- of ES4.

So what does AS3 add to ECMA-262? Those are also the differences to JavaScript:

  • Dynamically and statically typed code
  • Packages, Classes and Interfaces
  • Standard OO inheritance model (not prototype based, statically typed)
  • uint and int datatype
  • E4X (ECMA-357)
  • Type-safe conditional compilation (ES4)
  • Vector.<T> datatype (ES4)

Maybe I have forgotten some features. I am not sure if XML, XMLList etc. are already defined in 262 or came with 357.

The key difference however is the standard library. JavaScript comes with a couple of predefined classes like DOMElement and browser dependent additions. ActionScript has a fairly large standard library with features like video streaming and is consistent over all platforms.


I've been programming in both ActionScript and Javascript, and from a less-technical standpoint, I see two main differences.

1) JavaScript is more powerful. You are allowed to do much more with the language because it does not have a "compiler" or types. There are some great frameworks out there like ExtJS and jQuery that try and simplify things for you, but even with them, you are really allowed to do an amazing amount of damage if you want to.

2) ActionScript is much more confining and hence, much easier to maintain. Adobe did a lot of work to keep you out of the difficult parts of ECMAScript. ECMAScript Objects, prototypal inheritance, and closures are three concepts that you really don't need to understand to program in ActionScript. You just need to understand how to use Adobe's "Class" object.

For simple uses, I prefer JavaScript. However, once the project gets large, it depends who you are coding for. If I had a team of 5 developers programming at a scrappy start-up, I'd choose JavaScript in a heartbeat. However, in the girth of a large corporation, or academia, you might be safer relying on Adobe's platform.

Hope that helps.


One is type Safetly. Actionscript requires that you set a type for all objects, and JavaScript doesn't (for that matter, in JavaScript, one variable may be one type and then immediately set to another type).

Actionscript is object oriented. Although you can sort of have this in JavaScript, Actionscript allows for object inheritance, etc.


Essentially the main difference I find is that ActionScript is more a verbose statically-typed class-based language where as javascript is a prototypal language.

Unfortunately there is no type-inference in ActionScript so using Flex Builder gives a warning every time you leave something untyped which I find unnecessary and overly verbose, not only does it make it more verbose than javascript but I find equivalent code to be more verbose than C#.

However the extra verbosity does have yield perf improvements and extra type safety at compile-time. Unfortunately this also adds to build time quite significantly, in Java Script apps of any size I'm used to instant feedback whereas my last ActionScript project had build time exceeding 2 minutes.


From a developer point of view, what matter most:

1) Javascript is not really OOP, it has NO super keyword, which means if you override( by any means ) something, you can't call it through super, and this is the deal breaker for complex programs for which OOP is the key, and Actionscript3 is all OOP, you can have millions line of Actionscript3 code working together, and well maintained.

2) Actionscript3 runs in Flash Player which has only one implementation from Adobe, this means it's consistent all the time, all browsers( as long as installed Flash Player), but Javascript runs in browsers directly, but each browser has its own implementation, which means your Javascript code has to be tested against all targeted browsers to ensure working.


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


frankly it's not the same, cuz action script is loaded with EMQJ24, the new language for high development website. while JS still with it EMCA22, the difference between those are the style and format of the code. and also action script are ages enough, that's why most of programmer nowdays using CSX01 updated language from cSS,it can recognize all type off language without any line.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号