File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -52,14 +52,14 @@ new KeyboardEvent(type, options)
5252下面是一个示例。
5353
5454``` javascript
55- function showChar (e ){
55+ function showChar (e ) {
5656 console .log (' ALT: ' + e .altKey );
5757 console .log (' CTRL: ' + e .ctrlKey );
5858 console .log (' Meta: ' + e .metaKey );
5959 console .log (' Meta: ' + e .shiftKey );
6060}
6161
62- document .body .addEventListener (' click ' , showChar, false );
62+ document .body .addEventListener (' keydown ' , showChar, false );
6363```
6464
6565### KeyboardEvent.code
Original file line number Diff line number Diff line change @@ -19,7 +19,7 @@ var obj = {
1919
2020### 键名
2121
22- 对象的所有键名都是字符串(ES6 又引入了 Symbol 值也可以作为键值 ),所以加不加引号都可以。上面的代码也可以写成下面这样。
22+ 对象的所有键名都是字符串(ES6 又引入了 Symbol 值也可以作为键名 ),所以加不加引号都可以。上面的代码也可以写成下面这样。
2323
2424``` javascript
2525var obj = {
@@ -171,7 +171,7 @@ y // 1
171171
172172JavaScript 引擎读到上面这行代码,会发现可能有两种含义。第一种可能是,这是一个表达式,表示一个包含` foo ` 属性的对象;第二种可能是,这是一个语句,表示一个代码区块,里面有一个标签` foo ` ,指向表达式` 123 ` 。
173173
174- 为了避免这种歧义,JavaScript 规定 ,如果行首是大括号,一律解释为语句(即代码块)。如果要解释为表达式(即对象),必须在大括号前加上圆括号 。
174+ 为了避免这种歧义,V8 引擎规定 ,如果行首是大括号,一律解释为对象。不过,为了避免歧义,最好在大括号前加上圆括号 。
175175
176176``` javascript
177177({ foo: 123 })
You can’t perform that action at this time.
0 commit comments