javascript - @const 在 javascript 中?

标签 javascript google-closure-compiler

我正在阅读 http://google-styleguide.googlecode.com/svn/trunk/javascriptguide.xml当我在 Constant 部分注意到注释注释时:

/**
 * The number of seconds in each of the given units.
 * @type {Object.<number>}
 * @const
 */

然后指南继续说“这允许编译器强制执行常量。”

这是 v8 的东西吗?这是在哪里记录的?

我脑子里浮现出一种可能性,也许,只是也许,我可以为 v8(或其他)提供类型信息!

最佳答案

Google 的 Closure Compiler可以接受JSDoc comments ,它会生成警告或错误。

例如,如果您 try使用高级优化编译以下代码:

/** @const */ var MY_BEER = 'stout';

MY_BEER = 'bar';

它会产生一个错误:

Number of errors: 1

JSC_CONSTANT_REASSIGNED_VALUE_ERROR: constant MY_BEER assigned a value more than once at line 5 character 8

他们不鼓励使用 const 关键字,因为它不是 ECMAScript 标准的一部分。

关于javascript - @const 在 javascript 中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3421104/

相关文章:

javascript - 使用下拉菜单滑动的水平菜单

javascript - 在另一个 jquery 事件完成后播放声音

javascript - Jquery $(窗口).scrollTop();方法是滚动到页面的特定位置,然后再次滚动到页面顶部?

javascript - 垂直居中垂直文本

msbuild - 在构建服务器上将 Google Closure Compiler 与 MS Build 集成

javascript - Foundation CSS 框架的 Closure Compiler externs

javascript - Jquery PHP 图像 slider

java - 如何在java中使用 "closure-compiler "

node.js - Google Closure 编译器移动了?它给出了 302 错误

jquery - 带有 jQ​​uery 应用程序的 Google Closure 编译器