javascript - typescript lambda 错误

标签 javascript visual-studio visual-studio-2012 typescript

我正在观看 typescript 教程,有一次我必须编写这行代码

var squareItSimpler = function(h:number, w:number) => h * w;

但我就是无法让它工作。我不断收到错误

The command "C:\Program Files (x86)\Microsoft SDKs\TypeScript\tsc.exe"  --module AMD --target ES3....exited with code 1

我只是不知道该怎么办,我在这里做错了什么吗?

有趣的是下面的作品:

var squareItSimplest = (h:number, w:number) => h * w;

我正在使用 TypeScript 0.9.0.1

最佳答案

当您在 Typescript 中执行类似 lambda 表达式时,您会省略 function 关键字。也许您的教程有错误。

编辑 — 来自 the spec :

TypeScript supports arrow function expressions, a new feature planned for ECMAScript 6. Arrow function expressions are a compact form of function expressions that omit the function keyword and have lexical scoping of this.

关于javascript - typescript lambda 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17479172/

相关文章:

javascript - 如何修复 table thead 和可滚动的 tbody(thead 包含 3 行)

javascript - 在循环内的 AngularJs 中创建动态范围变量

c++ - 在 Visual Studio 2015 中使用 QCharts 时未解析的外部符号

c++ - 大括号或等于初始化程序在 Visual Studio 2015 RC 中导致 C2098 和 C2059

visual-studio-2010 - Visual Studio 解决方案资源管理器位置

visual-studio-2012 - 触发器正在阻止数据库项目发布

javascript - 当第一个选项卡处于事件状态时,第二个选项卡不起作用

javascript - Sequelizejs belongsToMany 与 otherKey 的关系

c++ - 在 __asm 中插入注释导致 C2400 错误 (VS2012)

visual-studio-2012 - Visual Studio : The Android SDK Directory could not be found. 请通过/p:AndroidSdkDirectory 设置