mirror of
https://github.com/ruanyf/es6tutorial.git
synced 2025-05-24 10:22:23 +00:00
Update symbol.md
demo不能在游览器上直接运行,故修改下;
This commit is contained in:
parent
591b05babe
commit
54eba0dc17
@ -163,13 +163,15 @@ let obj = {
|
||||
Symbol 类型还可以用于定义一组常量,保证这组常量的值都是不相等的。
|
||||
|
||||
```javascript
|
||||
const log = {};
|
||||
|
||||
log.levels = {
|
||||
DEBUG: Symbol('debug'),
|
||||
INFO: Symbol('info'),
|
||||
WARN: Symbol('warn')
|
||||
};
|
||||
log(log.levels.DEBUG, 'debug message');
|
||||
log(log.levels.INFO, 'info message');
|
||||
console.log(log.levels.DEBUG, 'debug message');
|
||||
console.log(log.levels.INFO, 'info message');
|
||||
```
|
||||
|
||||
下面是另外一个例子。
|
||||
|
Loading…
x
Reference in New Issue
Block a user