开发者

java keywords in javascript

according to this page http://www.quackit.com/javascript/javascript_reserved_words.cfm javascript has some keywords which are from java, re开发者_开发百科served. I also notice that with the highlighting in my editor. Is this to be future proof? Are they planning to implement some more OOP style operators into javascript?

I would love to se interfaces, abstract classes and things like that coming to js, but does the reservation of these words indicate anything?


From the ECMA-262 spec, §7.6.1.2 (Future Reserved Words):

java keywords in javascript

And, from §2 (Conformance):

A conforming implementation of ECMAScript is permitted to support program and regular expression syntax not described in this specification. In particular, a conforming implementation of ECMAScript is permitted to support program syntax that makes use of the "future reserved words" listed in 7.6.1.2 of this specification.


The words are reserved only to offer the original author (Brendan Eich) a starting point on which to build keywords.

In addition, JavaScript was designed with Java's syntax and standard library in mind. In particular, all Java keywords were reserved in original JavaScript, JavaScript's standard library follows Java's naming conventions, and JavaScript's Math and Date objects are based on classes from Java 1.0.

"JS had to “look like Java” only less so, be Java’s dumb kid brother or boy-hostage sidekick. Plus, I had to be done in ten days or something worse than JS would have happened" — Brendan Eich

There are currently no plans to integrate specific Java features into Javascript. The current roadmap suggests these features:

  • Classes
  • A module system
  • Optional type annotations and static typing, probably using a structural type system
  • Generators and iterators
  • Destructuring assignment
  • Algebraic data types


No they don't guarantee anything, they were originally reserved "just in case" and have stuck in the language since then. They may or may not get used but most will not be used in the near future.


@Andy and @OriginalSyn already answered your question and I just wanted to answer to this:

I would love to se interfaces, abstract classes and things like that coming to js, but does the reservation of these words indicate anything?

It's very unlikely that these constructions have ever appear in JavaScript. JS follows prototype-based OOP model which doesn't use things like classes. This model has some advantages over classical, class-based model and you'll have to love it or stop using JS as there is no real alternative for this language. ;)

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜