JavaScript是一种无类型语言吗? [英] Is JavaScript an untyped language?

查看:202
本文介绍了JavaScript是一种无类型语言吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发现有些人称JavaScript为动态,弱类型语言,但有些人甚至说无类型?这是真的吗?

I've found that some people call JavaScript a "dynamically, weakly typed" language, but some even say "untyped"? Which is it really?

推荐答案

JavaScript 无类型:

JavaScript is untyped:

http://no.gd/p/untyped-20120205-235300 .jpg

即使是Brendan Eich也是如此。在推特上,他回复了一个与这个问题相关的帖子:

Even Brendan Eich says so. On Twitter, he replied to a thread that linked to this question:


...学术类型使用无类型表示无静态类型......

所以问题是无类型有一些不同的定义。

So the problem is that there's a few different definitions of untyped.

一个定义已在一个定义中讨论过上述答案 - 运行时不标记值,只是将每个值视为位。 JavaScript 标记标记值,并根据这些标记具有不同的行为。所以JavaScript显然不适合这个类别。

One definition has been talked about in one of the above answers - the runtime doesn't tag values and just treats each value as bits. JavaScript does tag values and has different behaviour based on those tags. So JavaScript obviously doesn't fit this category.

另一个定义来自编程语言理论(Brendan所指的学术事物) 。在此域中,无类型仅表示一切都属于单一类型

The other definition is from Programming Language Theory (the academic thing that Brendan is referring to). In this domain, untyped just means everything belongs to a single type.

为什么?因为语言只有在能够证明类型对齐时才生成程序(又名 Curry-Howard对应;类型是定理,程序是证明)。这意味着使用无类型语言:

Why? Because a language will only generate a program when it can prove that the types align (a.k.a. the Curry-Howard correspondence; types are theorems, programs are proofs). This means in an untyped language:


  1. 程序始终生成

  2. 因此类型始终匹配

  3. 因此,必须只有一个类型

  1. A program is always generated
  2. Therefore types always match up
  3. Therefore there must only be one type

与输入语言相比:


  1. 程序可能不会生成

  2. 因为类型可能匹配

  3. 因为程序可以包含多个 types

  1. A program might not be generated
  2. Because types might not match up
  3. Because a program can contain multiple types

所以你去PLT,无类型只是意味着动态输入键入仅表示静态类型。 JavaScript在这个类别中绝对是无类型的。

So there you go, in PLT, untyped just means dynamically typed and typed just means statically typed. JavaScript is definitely untyped in this category.

参见:

这篇关于JavaScript是一种无类型语言吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆