]> code.delx.au - gnu-emacs-elpa/blob - README.md
Update README
[gnu-emacs-elpa] / README.md
1 js2-mode
2 ========
3
4 An improved JavaScript mode for GNU Emacs. Forked from <http://code.google.com/p/js2-mode/>.
5
6 Install
7 =======
8
9 $ git clone git://github.com/mooz/js2-mode.git
10 $ cd js2-mode
11 $ emacs --batch --eval '(byte-compile-file "js2-mode.el")'
12
13 Then, place js2-mode.elc into your site-lisp directory.
14
15 In you emacs config:
16
17 (autoload 'js2-mode "js2-mode" nil t)
18 (add-to-list 'auto-mode-alist '("\\.js$" . js2-mode))
19
20 See <http://code.google.com/p/js2-mode/wiki/InstallationInstructions> for details.
21
22 Differences between original js2-mode.el
23 ========================================
24
25 Supported more popular indentation style
26 ----------------------------------------
27
28 When js2-consistent-level-indent-inner-bracket-p is non-nil
29
30 [foo, bar, baz].forEach(function (v) {
31 if (validate(v))
32 process(v);
33 });
34
35 [a, b, c].some(function (v) {
36 return validate(v);
37 });
38
39 When js2-consistent-level-indent-inner-bracket-p is nil
40 (Same as original js2-mode's indentation)
41
42 [foo, bar, baz].forEach(function (v) {
43 if (validate(v))
44 process(v);
45 });
46
47 [a, b, c].some(function (v) {
48 return validate(v);
49 });
50
51 Fixed ugly indentation with multi-line variable declaration
52 -----------------------------------------------------------
53
54 In original js2-mode.el,
55
56 var foo = 10,
57 bar = 20,
58 baz = 30;
59
60 In this js2-mode.el,
61
62 var foo = 10,
63 bar = 20,
64 baz = 30;
65
66 Support for abbreviated destructuring assignments
67 -------------------------------------------------
68
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)
71
72 (function ({responseText}) { /* */ })(xhr); // As the argument of function
73
74 for (let [k, { name, age }] in Iterator(obj)) // nested
75 print(k, name, age);
76
77 Support for expression closure in property value
78 ------------------------------------------------
79
80 let worker = {
81 get age() 20,
82 get sex() "male",
83 fire: function () _fire()
84 };
85
86 Fixed odd indentation of "else if" with no braces
87 -----------------------------------------------------
88
89 In original js2-mode.el,
90
91 if (foo)
92 return foo;
93 else if (bar)
94 return bar; // here
95
96 In this js2-mode.el,
97
98 if (foo)
99 return foo;
100 else if (bar)
101 return bar; // fixed
102
103 Fixes in Imenu support
104 -----------------------
105
106 Supports element-get form:
107
108 foo["bar"] = function() {};
109 foo[647] = function() {};
110
111 Proper position for functions in nested object literals:
112
113 foo = {
114 bar: function() {}, // ok in original
115 baz: {
116 boop: function() {} // fixed here
117 },
118 }
119
120 Imenu support for nested named functions
121 ----------------------------------------
122
123 Supports one level of nesting:
124
125 function foo() {
126 function bar() { // shown as foo.bar
127 function baz() {} // hidden
128 }
129 }
130
131 Top-level function can be anonymous wrapper:
132
133 (function() {
134 var foo = function() {}; // shown as foo
135 })();
136
137 Examples of output:
138
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>
143
144 No support for library-specific extension methods, though, like _.extend.
145
146 Bugs
147 ====
148
149 If you find problems, please report them to <http://github.com/mooz/js2-mode/issues>.