javascript 和类似的脚本语言会从强类型中受益吗?

发布于 2024-08-01 18:59:51 字数 1432 浏览 12 评论 0原文

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

满意归宿 2024-08-08 18:59:51

它因无需键入而获得灵活性。 我个人喜欢弱类型语言。

所以答案是有利有弊。

对于想要在浏览器中使用强类型语言的人,可以使用 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.

欢你一世 2024-08-08 18:59:51

它绝对应该具有可用的强类型。 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.

风吹过旳痕迹 2024-08-08 18:59:51

JavaScript 和类似的脚本语言会从强类型中受益吗?

是的,他们会的,JavaScript 2.0 引入了 类型系统

类型系统
JavaScript 2.0 支持类型的概念,
它可以被认为是所有的子集
可能的值。 有一些内置的
类型,例如对象、数字和
细绳; 每个用户定义的类(第 6 节)
也是一种类型。

另请参阅:http:// timkadlec.com/2008/04/an-objective-look-at-javascript-2-0-strong-typing/

一般来说,对强类型的支持为编译和优化过程提供了许多有趣的机会。

Would javascript and similar scripting languages benefit from being strongly typed?

Yes, they would, JavaScript 2.0 introduces a type system:

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.

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.

情何以堪。 2024-08-08 18:59:51

我自己的意见:您可以在执行脚本之前对其进行解析。 这将捕获大多数类型错误,并且意味着用户不必看到部分执行然后终止的脚本结果。 更好的是,如果它有一个解析器,那么调试它会容易得多:)

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 :)

星星的軌跡 2024-08-08 18:59:51

我在很大程度上喜欢大多数脚本语言的弱类型方面。 除了性能之外,我想要强类型的唯一原因是工具重构强类型语言比弱类型语言更容易。

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.

伴我心暖 2024-08-08 18:59:51

早在那时,我就用 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.

肥爪爪 2024-08-08 18:59:51

微软在使用 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/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文