4 An improved JavaScript mode for GNU Emacs. Forked from <http://code.google.com/p/js2-mode/>.
9 $ git clone git://github.com/mooz/js2-mode.git
11 $ emacs --batch -f batch-byte-compile js2-mode.el
13 _NOTE: Emacs may fail to byte compile js2-mode.el in interactive mode (e.g., `M-x byte-compile-file`). Following the above instruction is highly recommended. See https://github.com/mooz/js2-mode/issues/13 for details._
15 Then, place js2-mode.elc into your site-lisp directory.
19 (autoload 'js2-mode "js2-mode" nil t)
20 (add-to-list 'auto-mode-alist '("\\.js$" . js2-mode))
22 See <http://code.google.com/p/js2-mode/wiki/InstallationInstructions> for details.
24 Differences between original js2-mode.el
25 ========================================
27 Popular indentation style
28 -------------------------
30 When `js2-consistent-level-indent-inner-bracket-p` is non-nil
32 [foo, bar, baz].forEach(function (v) {
37 [a, b, c].some(function (v) {
41 When `js2-consistent-level-indent-inner-bracket-p` is nil
42 (Same as original js2-mode's indentation)
44 [foo, bar, baz].forEach(function (v) {
49 [a, b, c].some(function (v) {
53 Pretty multi-line variable declaration
54 --------------------------------------
56 In original js2-mode.el,
62 In this js2-mode.el, when the value `js2-pretty-multiline-decl-indentation-p` is non-nil,
68 Abbreviated destructuring assignments
69 -------------------------------------
71 let {a, b} = {a: 10, b: 20}; // Abbreviated (Not supported in original js2-mode.el)
72 let {a: a, b: b} = {a: 10, b: 20}; // Same as above (Supported in original js2-mode.el)
74 (function ({responseText}) { /* */ })(xhr); // As the argument of function
76 for (let [k, { name, age }] in Iterator(obj)) // nested
79 Expression closure in property value
80 ------------------------------------
85 fire: function () _fire()
88 Fix for odd indentation of "else if" with no braces
89 ---------------------------------------------------
91 In original js2-mode.el,
105 Fixes in Imenu support
106 ----------------------
108 Supports element-get form:
110 foo["bar"] = function() {};
111 foo[647] = function() {};
113 Proper position for functions in nested object literals:
116 bar: function() {}, // ok in original
118 boop: function() {} // fixed here
122 Imenu support for function nesting
123 ----------------------------------
125 Supports one level of nesting:
128 function bar() { // shown as foo.bar
129 function baz() {} // hidden
133 Top-level function can be anonymous wrapper:
136 var foo = function() {}; // shown as foo
141 * [Underscore.js](https://github.com/documentcloud/underscore/blob/master/underscore.js)
142 -> <https://gist.github.com/824262>
143 * [Backbone.js](https://github.com/documentcloud/backbone/blob/master/backbone.js)
144 -> <https://gist.github.com/824260>
146 No support for library-specific extension methods like _.extend.
148 Highlights undeclared/external variables
149 ----------------------------------------
151 Original mode highlights them only on the left side of assignments:
154 hose = new House(); // highlights "hose"
156 Here they are highlighted in all expressions:
158 function feed(fishes, food) {
159 for each (var fish in fshes) { // highlights "fshes"
160 food.feed(fsh); // highlights "fsh"
162 hood.discard(); // highlights "hood"
165 Destructuring assignments and array comprehensions (JS 1.7) are supported:
167 let three, [one, two] = [1, 2];
168 thee = one + two; // highlights "thee"
170 function revenue(goods) {
171 // highlights "coast"
172 return [price - coast for each ({price, cost} in goods)].reduce(add);
178 If you find problems, please report them to <http://github.com/mooz/js2-mode/issues>.