|
1225 | 1225 |
|
1226 | 1226 | - Constant values |
1227 | 1227 |
|
1228 | | - If a value is intended to be constant and immutable, it should be given a name in `CONSTANT_VALUE_CASE`. `ALL_CAPS` additionally implies @const (that the value is not overwritable). |
| 1228 | + If a value is intended to be constant and immutable, it should be given a name in `CONSTANT_VALUE_CASE`. `ALL_CAPS` additionally implies `@const` (that the value is not overwritable). |
1229 | 1229 |
|
1230 | 1230 | Primitive types (number, string, boolean) are constant values. |
1231 | 1231 |
|
1232 | 1232 | Objects' immutabilty is more subjective — objects should be considered immutable only if they do not demonstrate obeserverable state change. This is not enforced by the compiler. |
1233 | 1233 |
|
1234 | 1234 | - Constant pointers (variables and properties) |
1235 | 1235 |
|
1236 | | - The @const annotation on a variable or property implies that it is not overwritable. This is enforced by the compiler at build time. This behavior is consistent with the const keyword (which we do not use due to the lack of support in Internet Explorer). |
| 1236 | + The `@const` annotation on a variable or property implies that it is not overwritable. This is enforced by the compiler at build time. This behavior is consistent with the const keyword (which we do not use due to the lack of support in Internet Explorer). |
1237 | 1237 |
|
1238 | | - A @const annotation on a method additionally implies that the method should not be overriden in subclasses. |
| 1238 | + A `@const` annotation on a method additionally implies that the method should not be overriden in subclasses. |
1239 | 1239 |
|
1240 | 1240 | **Examples** |
1241 | 1241 |
|
1242 | | - Note that @const does not necessarily imply `CONSTANT_VALUES_CASE`. However, `CONSTANT_VALUES_CASE` does imply @const. |
| 1242 | + Note that `@const` does not necessarily imply `CONSTANT_VALUES_CASE`. However, `CONSTANT_VALUES_CASE` does imply `@const`. |
1243 | 1243 |
|
1244 | 1244 | ```javascript |
1245 | 1245 | /** |
|
1249 | 1249 | goog.example.TIMEOUT_IN_MILLISECONDS = 60; |
1250 | 1250 | ``` |
1251 | 1251 |
|
1252 | | - The number of seconds in a minute never changes. It is a constant value. `ALL_CAPS` also implies @const, so the constant cannot be overwritten. |
| 1252 | + The number of seconds in a minute never changes. It is a constant value. `ALL_CAPS` also implies `@const`, so the constant cannot be overwritten. |
1253 | 1253 |
|
1254 | 1254 | The open source compiler will allow the symbol it to be overwritten because the constant is not marked as @const. |
1255 | 1255 |
|
|
1270 | 1270 | ## <a name='accessors'>Accessors</a> |
1271 | 1271 |
|
1272 | 1272 | - Accessor functions for properties are not required |
1273 | | - - If you do make accessor functions use getVal() and setVal('hello') |
| 1273 | + - If you do make accessor functions use `getVal()` and `setVal('hello')` |
1274 | 1274 |
|
1275 | 1275 | ```javascript |
1276 | 1276 | // bad |
|
1286 | 1286 | dragon.setAge(25); |
1287 | 1287 | ``` |
1288 | 1288 |
|
1289 | | - - If the property is a boolean, use isVal() or hasVal() |
| 1289 | + - If the property is a boolean, use `isVal()` or `hasVal()` |
1290 | 1290 |
|
1291 | 1291 | ```javascript |
1292 | 1292 | // bad |
|
1300 | 1300 | } |
1301 | 1301 | ``` |
1302 | 1302 |
|
1303 | | - - It's okay to create get() and set() functions, but be consistent. |
| 1303 | + - It's okay to create `get()` and `set()` functions, but be consistent. |
1304 | 1304 |
|
1305 | 1305 | ```javascript |
1306 | 1306 | function Jedi(options) { |
|
1392 | 1392 |
|
1393 | 1393 | - The module should start with a `!`. This ensures that if a malformed module forgets to include a final semicolon there aren't errors in production when the scripts get concatenated. |
1394 | 1394 | - The file should be named with camelCase, live in a folder with the same name, and match the name of the single export. |
1395 | | - - Add a method called noConflict() that sets the exported module to the previous version and returns this one. |
| 1395 | + - Add a method called `noConflict()` that sets the exported module to the previous version and returns this one. |
1396 | 1396 | - Always declare `'use strict';` at the top of the module. |
1397 | 1397 |
|
1398 | 1398 | ```javascript |
|
0 commit comments