Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
552 views
in Technique[技术] by (71.8m points)

compiler construction - Typesafe Javascript

Is there a way to enforce types in JavaScript? I'm thinking of a pre-processor which takes an input file written in ActionScript 3 or Java and converts it to JS.

I do not need a big run-time apparatus, I just need to introduce the idea of compile-time in my workflow and run the trivial compile-time checks on my code (and also use interfaces). Neither I need the API from Java or Flex, just the syntax.

The standard browser-functions could also be checked against the IDL definitions, but it is not a must.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Whilst I'm a little late to this party, I think it's definitely worth mentioning Dart (which is a Google product) and TypeScript (which is a Microsoft product).

JavaScript is fast becoming an extremely popular language as applications become more web based. However as you have pointed out, JavaScript lacks type safety, and to name a few other things; classes, interfaces and packages/namespaces/modules.

This is where Dart and TypeScript step in. These languages are essentially supersets of JavaScript. When you write Dart or TypeScript code, it is compiled into clean, standards compliant JavaScript.

The benefits of Dart and TypeScript are that they provide type safety, interfaces, classes etc. Thus allowing you to write cleaner, scalable, manageable applications, which still run in the browser.

Being a Microsoft oriented programmer, I've had a lot of experience with TypeScript, including being somewhat active in the development of the language (you can find information for TypeScript development at codeplex)

My only concern at the moment is that TypeScript is lacking in some fundamental features. It seems that some of the current implementation (0.9.0 alpha) has some equally gaping holes that might deter the savvy developer from using it at the moment (subject to change of course).

I cannot really comment on Dart, as I have only used this a few times, but my overall experience with Dart was good!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...