Javascript 编译器 Traceur

码农软件 · 软件分类 · 编译器 · 2019-12-08 13:58:38

软件介绍

Traceur 是一个来自 Google 的 Javascript 编译器,通过它可以体验一些很新并且有趣的 Javascript 语言特性,这些多数是还没有被当前浏览器实现的 ECMAScript 标准或草案,比如:数组比较、类、模块、迭代器、方法参数默认值、Promise等。

以下是几个例子:

数组比较(Array Comprehension):

var array = [for (x of [0, 1, 2]) for (y of [0, 1, 2]) x + '' + y];
expect(array).to.be.eql([
  '00', '01', '02', '10', '11', '12', '20', '21', '22'
]);

更精简的函数定义语法(Arrow Functions):

var square = (x) => {
  return x * x;
};
var square2 = x => x * x;
var objectify = x => ({ value: x }); // Immediate return of an object literal must be wrapped in parentheses
expect(square(4)).to.be.eql(16);
expect(square2(4)).to.be.eql(16);
expect(objectify(1)).to.be.eql({ value: 1 });

Promises:

function timeout(ms) {
  return new Promise((resolve) => {
    setTimeout(resolve, ms);
  });
}
timeout(100).then(() => {
  console.log('done');
});

更详细的语言特性列表,请参考:https://github.com/google/traceur-compiler/wiki/LanguageFeatures

本文地址:https://codercto.com/soft/d/20700.html

Pro Git

Pro Git

Scott Chacon / Apress / 2009-8-27 / USD 34.99

Git is the version control system developed by Linus Torvalds for Linux kernel development. It took the open source world by storm since its inception in 2005, and is used by small development shops a......一起来看看 《Pro Git》 这本书的介绍吧!

JS 压缩/解压工具
JS 压缩/解压工具

在线压缩/解压 JS 代码

Base64 编码/解码
Base64 编码/解码

Base64 编码/解码

UNIX 时间戳转换
UNIX 时间戳转换

UNIX 时间戳转换