admin管理员组文章数量:1201983
We are considering adopting the Google JavaScript coding guidelines within our company to maintain consistency across projects but one thing is confusing me. In the section on constants it says to use the @const
keyword annotation for compile-time constant enforcement but I have never come across the @
symbol before. Is this a Google extension or part of the core language?
Here is the full text:
For non-primitives, use the
@const
annotation.
/**
* The number of seconds in each of the given units.
* @type {Object.<number>}
* @const
*/
goog.example.SECONDS_TABLE = {
minute: 60,
hour: 60 * 60
day: 60 * 60 * 24
}
This allows the compiler to enforce constant-ness.
As for the
const
keyword, Internet Explorer doesn't parse it, so don't use it.
We are considering adopting the Google JavaScript coding guidelines within our company to maintain consistency across projects but one thing is confusing me. In the section on constants it says to use the @const
keyword annotation for compile-time constant enforcement but I have never come across the @
symbol before. Is this a Google extension or part of the core language?
Here is the full text:
For non-primitives, use the
@const
annotation.
/**
* The number of seconds in each of the given units.
* @type {Object.<number>}
* @const
*/
goog.example.SECONDS_TABLE = {
minute: 60,
hour: 60 * 60
day: 60 * 60 * 24
}
Share Improve this question asked Jun 17, 2011 at 11:21 WheelieWheelie 3,9062 gold badges35 silver badges39 bronze badgesThis allows the compiler to enforce constant-ness.
As for the
const
keyword, Internet Explorer doesn't parse it, so don't use it.
2 Answers
Reset to default 17JSDoc annotations as this one can be used to give hints to the Google Closure Compiler as described in this page. Again, this is not part of the language, and the use of @constant (beside adding some information for your fellow programmer) is relevant only if you use the closure compiler in your project.
Hope this will help :)
Looks like it's referring to the use of @const in JSDoc (Think JavaDoc) to mark certain objects constant.
It's not a javascript keyword and not a part of the language – just something used in inline documentation in JSDoc.
Edit: The mention of 'never use the const keyword' may confuse you. The guidelines tell not to use const because IE doesn't support it, instead marking the "constants" constant in the documentation.
Some javascript compiler might parse JSdoc for notation like that, but I doubt it's standard.
本文标签: coding stylewhat does const mean in JavaScriptStack Overflow
版权声明:本文标题:coding style - what does @const mean in JavaScript? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1738599213a2101966.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论