JavaScript 和 ActionScript 3 之间的主要区别是什么?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2268276/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-22 23:32:22  来源:igfitidea点击:

What are the key differences between JavaScript and ActionScript 3?

javascriptactionscript-3porting

提问by Todd Moses

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 freezeand sealin EMCAScript-262 5th edition and such. I was wondering what the differences are?

我知道这两种语言都来自同一个 ECMA-262 标准。看来,这两个正在成为使用JavaScript通过类似的方法增加对核心对象实例的事件监听器非常相似freeze,并seal在EMCAScript-262第5版和这样的。我想知道有什么区别?

采纳答案by Joa Ebert

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

首先,ActionScript 3 和 JavaScript 都是在ECMA-262 中定义的,因此它们有很多共同点。例如,两种语言都具有原型继承功能。然而,ActionScript 完全实现ES4是不正确的。

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

ActionScript 实现了一些 ECMA-262 和 ES4 中未定义的一些特性——但绝对不是全部。

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

那么 AS3 为 ECMA-262 添加了什么?这些也是与 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)
  • 动态和静态类型代码
  • 包、类和接口
  • 标准的 OO 继承模型(不是基于原型的,静态类型的)
  • uint 和 int 数据类型
  • E4X (ECMA-357)
  • 类型安全的条件编译 (ES4)
  • Vector.<T> 数据类型 (ES4)

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

也许我忘记了一些功能。我不确定 XML、XMLList 等是否已经在 262 中定义或随 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.

然而,关键的区别在于标准库。JavaScript 附带了几个预定义的类,如 DOMElement 和浏览器相关的添加项。ActionScript 有一个相当大的标准库,具有视频流等功能,并且在所有平台上都是一致的。

回答by Stephano

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

我一直在使用 ActionScript 和 Javascript 进行编程,从技术含量较低的角度来看,我看到了两个主要区别。

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 ExtJSand jQuerythat 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.

1) JavaScript 更强大。你可以用这种语言做更多的事情,因为它没有“编译器”或类型。有一些很棒的框架,比如ExtJSjQuery,它们会尝试为您简化事情,但即使使用它们,如果您愿意,您也确实可以造成惊人的破坏。

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.

2) ActionScript 更受限制,因此更容易维护。Adobe 做了很多工作来让您远离 ECMAScript 的困难部分。ECMAScript 对象、原型继承和闭包是您在 ActionScript 中编程时不需要真正了解的三个概念。您只需要了解如何使用 Adob​​e 的“Class”对象。

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.

对于简单的使用,我更喜欢 JavaScript。但是,一旦项目变大,这取决于您为谁编码。如果我有一个由 5 名开发人员组成的团队在一个斗志旺盛的初创公司编程,我会立即选择 JavaScript。但是,在大公司或学术界的范围内,您可能更安全地依赖 Adob​​e 的平台。

Hope that helps.

希望有帮助。

回答by Gabriel McAdams

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 要求您为所有对象设置类型,而 JavaScript 则不需要(就此而言,在 JavaScript 中,一个变量可能是一种类型,然后立即设置为另一种类型)。

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

Actionscript 是面向对象的。尽管您可以在 JavaScript 中使用它,但 Actionscript 允许对象继承等。

回答by mythz

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.

本质上,我发现的主要区别在于 ActionScript 更像是一种冗长的静态类型的基于类的语言,而 javascript 是一种原型语言。

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#.

不幸的是,ActionScript 中没有类型推断,所以每次使用 Flex Builder 都会发出警告,当你留下一些我觉得不必要且过于冗长的未输入内容时,它不仅使它比 javascript 更冗长,而且我发现等效代码比 javascript 更冗长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.

然而,额外的冗长确实在编译时产生了性能改进和额外的类型安全性。不幸的是,这也显着增加了构建时间,在任何规模的 Java Script 应用程序中,我习惯于即时反馈,而我上一个 ActionScript 项目的构建时间超过 2 分钟。

回答by Paul Sweatte

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.

主要区别在于 ActionScript 3 支持基于类的继承和原型继承,在类名和文件名之间强制执行命名空间绑定,并且不支持某些全局 JavaScript 方法,例如eval. 幸运的是,您可以做几件事来弥补差距。

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

您可以使用 ES for ECMAScript 或 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.

如果您使用的是 AS3 命名空间,则任何方法重写都必须使用 AS3 命名空间和 override 属性。

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

如果您不使用 AS3 命名空间,则可以使用原型方法和propertyIsEnumerable.

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

您可以有选择地在动态函数中使用属性或方法的 AS3 命名空间版本:

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

要关闭基于类的继承,您还可以使用以下编译器选项: 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.

如果不使用 AS3 命名空间,核心类的实例将继承原型对象上定义的属性和方法。

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

如果您决定使用 AS3 命名空间,核心类的实例将继承类定义中定义的属性和方法。

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

以下是 ECMAScript-4 和 ECMAScript-2017 或更高版本之间的共同特性:

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

参考

回答by user2336415

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.

1) Javascript 并不是真正的 OOP,它没有 super 关键字,这意味着如果你覆盖(以任何方式)某些东西,你不能通过 super 调用它,这是 OOP 是关键的复杂程序的交易破坏者, Actionscript3 都是面向对象的,你可以让数百万行 Actionscript3 代码一起工作,并且维护得很好。

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.

2)Actionscript3运行在Flash Player中,Adobe只有一个实现,这意味着它一直都是一致的,所有浏览器(只要安装了Flash Player),但是Javascript直接运行在浏览器中,但每个浏览器都有自己的实现,这意味着您的 Javascript 代码必须针对所有目标浏览器进行测试以确保正常工作。

回答by kean

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.

坦白说不一样,因为动作脚本加载了EMQJ24,高开发网站的新语言。虽然JS仍然使用EMCA22,但它们之间的区别在于代码的样式和格式。而且动作脚本已经足够老了,这就是为什么现在大多数程序员使用来自 cSS 的 CSX01 更新语言,它可以识别所有类型的语言而无需任何行。