拥有该功能没有任何缺点,我不得不说,对于中等到大型的项目,强类型可以防止大量问题。 为了充分利用它,您需要 IDE 支持,以便它可以报告错误并提供自动完成选项,但如果 Javascript 具有真正的类和强类型,那么它将处于一个全新的世界。
It should definitely have strong typing available. Actionscript 3 is strongly typed, but still has prototype inheritance and a wildcard type if you need dynamic objects.
There are no downsides to having that feature available, and I have to say, for a project of moderate to large size, strong typing prevents A TON of problems. To get the most out of it you need IDE support so it can report errors and provide autocomplete options, but Javascript would be in a whole new world if it had real classes and strong typing.
Type System JavaScript 2.0 supports the notion of a type, which can be thought of as a subset of all possible values. There are some built-in types such as Object, Number, and String; each user-defined class (section 6) is also a type.
My own oppinion: You could parse scripts before executing them. This would catch most type-errors, and mean that the user doesn't have to see a partly-executed-then-terminated scriptresult. Even better, it would be a lot easier to debug the thing, if it had a parser :)
I like the weak typed aspects of most scripting languages for the most part. The only reason that I would want strongly typed, besides for performance, is that it is easier for tools to refactor strongly typed languages than weak.
I build a rapid prototype framework for eLearning in ActionScript 2 way back when. My biggest gripe was AS2 was not strongly typed and it causes me many a headache when debugging. I think that strongly typing things makes code easier to read. I think a weakly typed language offers more flexibility.
I lean more towards readability when i have to go back and figure out what the heck is going on in code i wrote 6 months ago.
发布评论
评论(7)
它因无需键入而获得灵活性。 我个人喜欢弱类型语言。
所以答案是有利有弊。
对于想要在浏览器中使用强类型语言的人,可以使用 GWT 和 Script#。
It gains flexibility from not being typed. I personally enjoy the weakly typed languages.
So the answer is there'd be benefits and drawbacks.
For people who want a strongly-typed language in the browser, GWT and Script# are available.
它绝对应该具有可用的强类型。 Actionscript 3 是强类型的,但如果您需要动态对象,仍然具有原型继承和通配符类型。
拥有该功能没有任何缺点,我不得不说,对于中等到大型的项目,强类型可以防止大量问题。 为了充分利用它,您需要 IDE 支持,以便它可以报告错误并提供自动完成选项,但如果 Javascript 具有真正的类和强类型,那么它将处于一个全新的世界。
It should definitely have strong typing available. Actionscript 3 is strongly typed, but still has prototype inheritance and a wildcard type if you need dynamic objects.
There are no downsides to having that feature available, and I have to say, for a project of moderate to large size, strong typing prevents A TON of problems. To get the most out of it you need IDE support so it can report errors and provide autocomplete options, but Javascript would be in a whole new world if it had real classes and strong typing.
是的,他们会的,JavaScript 2.0 引入了 类型系统:
另请参阅:http:// timkadlec.com/2008/04/an-objective-look-at-javascript-2-0-strong-typing/
一般来说,对强类型的支持为编译和优化过程提供了许多有趣的机会。
Yes, they would, JavaScript 2.0 introduces a type system:
Also see: http://timkadlec.com/2008/04/an-objective-look-at-javascript-2-0-strong-typing/
In general, support for strong typing provides many interesting opportunities for the compilation and optimization passes.
我自己的意见:您可以在执行脚本之前对其进行解析。 这将捕获大多数类型错误,并且意味着用户不必看到部分执行然后终止的脚本结果。 更好的是,如果它有一个解析器,那么调试它会容易得多:)
My own oppinion: You could parse scripts before executing them. This would catch most type-errors, and mean that the user doesn't have to see a partly-executed-then-terminated scriptresult. Even better, it would be a lot easier to debug the thing, if it had a parser :)
我在很大程度上喜欢大多数脚本语言的弱类型方面。 除了性能之外,我想要强类型的唯一原因是工具重构强类型语言比弱类型语言更容易。
I like the weak typed aspects of most scripting languages for the most part. The only reason that I would want strongly typed, besides for performance, is that it is easier for tools to refactor strongly typed languages than weak.
早在那时,我就用 ActionScript 2 构建了一个用于电子学习的快速原型框架。 我最大的抱怨是 AS2 不是强类型的,这让我在调试时非常头疼。 我认为强类型化会让代码更容易阅读。 我认为弱类型语言提供了更大的灵活性。
当我必须回去弄清楚我 6 个月前编写的代码到底发生了什么时,我更倾向于可读性。
I build a rapid prototype framework for eLearning in ActionScript 2 way back when. My biggest gripe was AS2 was not strongly typed and it causes me many a headache when debugging. I think that strongly typing things makes code easier to read. I think a weakly typed language offers more flexibility.
I lean more towards readability when i have to go back and figure out what the heck is going on in code i wrote 6 months ago.
微软在使用 TypeScript 解决过渡期间的强类型问题方面已经走了很长的路。 看一下:
http://www.typescriptlang.org/
Microsoft has gone a long way to solving strong typing the problem in the interim with typescript. Have a look:
http://www.typescriptlang.org/