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 function nesting and anonymous wrappers:
128 var foo = function() {
129 function bar() { // shown as foo.bar.<definition-1>
130 function baz() {} // foo.bar.baz
131 var qux = function() {}; // foo.bar.quux
138 * [jQuery 1.5](https://gist.github.com/845449)
139 * [Underscore.js](https://gist.github.com/824262)
140 * [Backbone.js](https://gist.github.com/824260)
142 No support for library-specific extension methods like $.extend.
144 Highlights undeclared/external variables
145 ----------------------------------------
147 Original mode highlights them only on the left side of assignments:
150 hose = new House(); // highlights "hose"
152 Here they are highlighted in all expressions:
154 function feed(fishes, food) {
155 for each (var fish in fshes) { // highlights "fshes"
156 food.feed(fsh); // highlights "fsh"
158 hood.discard(); // highlights "hood"
161 Destructuring assignments and array comprehensions (JS 1.7) are supported:
163 let three, [one, two] = [1, 2];
164 thee = one + two; // highlights "thee"
166 function revenue(goods) {
167 // highlights "coast"
168 return [price - coast for each ({price, cost} in goods)].reduce(add);
174 If you find problems, please report them to <http://github.com/mooz/js2-mode/issues>.