]> code.delx.au - gnu-emacs-elpa/blob - NEWS.md
Highlight JS snippets
[gnu-emacs-elpa] / NEWS.md
1 # History of user-visible changes
2
3 ## 20141115
4
5 Support for:
6
7 * Unicode characters in identifiers (improved).
8 * [Delegating yield](http://wiki.ecmascript.org/doku.php?id=harmony:generators#delegating_yield).
9 * [ES6 numeric literals](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-literals-numeric-literals) (octal, binary).
10 * Harmony [array and generator comprehensions](http://wingolog.org/archives/2014/03/07/es6-generator-and-array-comprehensions-in-spidermonkey).
11
12 ## 20131106
13
14 Support for:
15
16 * [Arrow functions](http://wiki.ecmascript.org/doku.php?id=harmony:arrow_function_syntax)
17 * [Generators](http://wiki.ecmascript.org/doku.php?id=harmony:generators)
18 * [Spread operator](http://wiki.ecmascript.org/doku.php?id=harmony:spread)
19
20 ## 20130510
21
22 ### Support for JSLint global declaration
23
24 See the docstring for `js2-include-jslint-globals`.
25
26 ## 20130216
27
28 ### We don't rebind `RET` anymore
29
30 Because well-behaving major modes aren't supposed to do that.
31
32 So pressing it won't continue a block comment, or turn a string into a concatenation.
33 Pressing `M-j`, however, will.
34
35 The options `js2-indent-on-enter-key` and `js2-enter-indents-newline` were also removed.
36
37 To bring back the previous behavior, put this in your init file:
38
39 ```js
40 (eval-after-load 'js2-mode
41 '(define-key js2-mode-map (kbd "RET") 'js2-line-break))
42 ```
43
44 ## 20120617
45
46 ### Support for [default](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/default_parameters) and [rest](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/rest_parameters) parameters
47
48 ## 20120614
49
50 ### Support for [for..of loops](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for...of)
51
52 ## Older changes
53
54 ### Popular indentation style
55
56 ```js
57 [foo, bar, baz].forEach(function (v) {
58 if (validate(v))
59 process(v);
60 });
61
62 [a, b, c].some(function (v) {
63 return validate(v);
64 });
65 ```
66
67 ### Pretty multiline variable declaration
68
69 In the original mode,
70
71 ```js
72 var foo = 10,
73 bar = 20,
74 baz = 30;
75 ```
76
77 In this mode when the value of `js2-pretty-multiline-declarations` is non-nil,
78
79 ```js
80 var foo = 10,
81 bar = 20,
82 baz = 30;
83 ```
84
85 ### Abbreviated destructuring assignments
86
87 ```js
88 let {a, b} = {a: 10, b: 20}; // Abbreviated (Not supported in the original mode)
89 let {a: a, b: b} = {a: 10, b: 20}; // Same as above (Supported in the original mode)
90
91 (function ({responseText}) { /* */ })(xhr); // As the argument of function
92
93 for (let [k, { name, age }] in Iterator(obj)) // nested
94 print(k, name, age);
95 ```
96
97 ### Expression closure in property value
98
99 ```js
100 let worker = {
101 get age() 20,
102 get sex() "male",
103 fire: function () _fire()
104 };
105 ```
106
107 ### Fix for odd indentation of "else if" with no braces
108
109 In the original mode,
110
111 ```js
112 if (foo)
113 return foo;
114 else if (bar)
115 return bar; // here
116 ```
117
118 In this mode,
119
120 ```js
121 if (foo)
122 return foo;
123 else if (bar)
124 return bar; // fixed
125 ```
126
127 ### Imenu support for function nesting
128
129 Supports function nesting and anonymous wrappers:
130
131 ```js
132 (function() {
133 var foo = function() {
134 function bar() { // shown as foo.bar.<definition-1>
135 function baz() {} // foo.bar.baz
136 var qux = function() {}; // foo.bar.quux
137 }
138 };
139 });
140 ```
141
142 Examples of output:
143
144 * [jQuery 1.5](https://gist.github.com/845449)
145 * [Underscore.js](https://gist.github.com/824262)
146 * [Backbone.js](https://gist.github.com/824260)
147
148 For library-specific extension methods like `$.extend` and `dojo.declare`, see [js2-imenu-extras](/mooz/js2-mode/blob/master/js2-imenu-extras.el).
149
150 ### Undeclared/external variables highlighting
151
152 Original mode highlights them only on the left side of assignments:
153
154 ```js
155 var house;
156 hose = new House(); // highlights "hose"
157 ```
158
159 Here they are highlighted in all expressions:
160
161 ```js
162 function feed(fishes, food) {
163 for each (var fish in fshes) { // highlights "fshes"
164 food.feed(fsh); // highlights "fsh"
165 }
166 hood.discard(); // highlights "hood"
167 }
168 ```
169
170 Destructuring assignments and array comprehensions (JS 1.7) are supported:
171
172 ```js
173 let three, [one, two] = [1, 2];
174 thee = one + two; // highlights "thee"
175
176 function revenue(goods) {
177 // highlights "coast"
178 return [price - coast for each ({price, cost} in goods)].reduce(add);
179 }
180 ```