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 Then, place js2-mode.elc into your site-lisp directory.
17 (autoload 'js2-mode "js2-mode" nil t)
18 (add-to-list 'auto-mode-alist '("\\.js$" . js2-mode))
20 See <http://code.google.com/p/js2-mode/wiki/InstallationInstructions> for details.
22 Differences between original js2-mode.el
23 ========================================
25 Popular indentation style
26 -------------------------
28 When `js2-consistent-level-indent-inner-bracket-p` is non-nil
30 [foo, bar, baz].forEach(function (v) {
35 [a, b, c].some(function (v) {
39 When `js2-consistent-level-indent-inner-bracket-p` is nil
40 (Same as original js2-mode's indentation)
42 [foo, bar, baz].forEach(function (v) {
47 [a, b, c].some(function (v) {
51 Pretty multi-line variable declaration
52 --------------------------------------
54 In original js2-mode.el,
60 In this js2-mode.el, when the value `js2-pretty-multiline-decl-indentation-p` is non-nil,
66 Abbreviated destructuring assignments
67 -------------------------------------
69 let {a, b} = {a: 10, b: 20}; // Abbreviated (Not supported in original js2-mode.el)
70 let {a: a, b: b} = {a: 10, b: 20}; // Same as above (Supported in original js2-mode.el)
72 (function ({responseText}) { /* */ })(xhr); // As the argument of function
74 for (let [k, { name, age }] in Iterator(obj)) // nested
77 Expression closure in property value
78 ------------------------------------
83 fire: function () _fire()
86 Fix for odd indentation of "else if" with no braces
87 ---------------------------------------------------
89 In original js2-mode.el,
103 Fixes in Imenu support
104 ----------------------
106 Supports element-get form:
108 foo["bar"] = function() {};
109 foo[647] = function() {};
111 Proper position for functions in nested object literals:
114 bar: function() {}, // ok in original
116 boop: function() {} // fixed here
120 Imenu support for function nesting
121 ----------------------------------
123 Supports one level of nesting:
126 function bar() { // shown as foo.bar
127 function baz() {} // hidden
131 Top-level function can be anonymous wrapper:
134 var foo = function() {}; // shown as foo
139 * [Underscore.js](https://github.com/documentcloud/underscore/blob/master/underscore.js)
140 -> <https://gist.github.com/824262>
141 * [Backbone.js](https://github.com/documentcloud/backbone/blob/master/backbone.js)
142 -> <https://gist.github.com/824260>
144 No support for library-specific extension methods like _.extend.
146 Highlights undeclared/external variables
147 ----------------------------------------
149 Original mode highlights them only on the left side of assignments:
152 hose = new House(); // highlights "hose"
154 Here they are highlighted in all expressions:
156 function feed(fishes, food) {
157 for each (var fish in fshes) { // highlights "fshes"
158 food.feed(fsh); // highlights "fsh"
160 hood.discard(); // highlights "hood"
163 Destructuring assignments and array comprehensions (JS 1.7) are supported:
165 let three, [one, two] = [1, 2];
166 thee = one + two; // highlights "thee"
168 function revenue(goods) {
169 // highlights "coast"
170 return [price - coast for each ({price, cost} in goods)].reduce(add);
176 If you find problems, please report them to <http://github.com/mooz/js2-mode/issues>.