From 52749d67225f056c906a3df43ddcdd4e4db1eeaa Mon Sep 17 00:00:00 2001 From: Doug Kearns Date: Sat, 14 Nov 2009 23:07:56 +1100 Subject: [PATCH] Remove some redundant uses of "new". --- HACKING | 4 +++- common/content/autocommands.js | 4 ++-- common/content/bookmarks.js | 8 ++++---- common/content/buffer.js | 2 +- common/content/commandline.js | 2 +- common/content/commands.js | 6 +++--- common/content/completion.js | 4 ++-- common/content/hints.js | 2 +- common/content/liberator.js | 2 +- common/content/mappings.js | 4 ++-- common/content/options.js | 2 +- common/content/style.js | 4 ++-- 12 files changed, 23 insertions(+), 21 deletions(-) diff --git a/HACKING b/HACKING index f8e1db72..cc8a0788 100644 --- a/HACKING +++ b/HACKING @@ -85,6 +85,8 @@ don't use them when the resulting code is hard to read. * Prefer lambda-style functions where suitable: Right: list.filter(function (elem) elem.good != elem.BAD); Wrong: list.filter(function (elem) { return elem.good != elem.BAD }); + Right: list.forEach(function (elem) { window.alert(elem); }); + Wrong: list.forEach(function (elem) window.alert(elem)); * Anonymous function definitions should be formatted with a space after the keyword "function". Example: function () {}, not function() {}. @@ -94,7 +96,7 @@ don't use them when the resulting code is hard to read. https://developer.mozilla.org/en/New_in_JavaScript_1.7#Block_scope_with_let * Reuse common local variable names E.g. "elem" is generally used for element, - "win" for windows etc. + "win" for windows, "func" for functions, "ret" for return values etc. * Prefer // over /* */ comments (exceptions for big comments are usually OK) Right: if (HACK) // TODO: remove hack diff --git a/common/content/autocommands.js b/common/content/autocommands.js index 55b53173..18141a1e 100644 --- a/common/content/autocommands.js +++ b/common/content/autocommands.js @@ -6,7 +6,7 @@ /** @scope modules */ -const AutoCommand = new Struct("event", "pattern", "command"); +const AutoCommand = Struct("event", "pattern", "command"); /** * @instance autocommands @@ -36,7 +36,7 @@ const AutoCommands = Module("autocommands", { liberator.log("DEPRECATED: the events list arg to autocommands.add() should be an array of event names"); } events.forEach(function (event) { - this._store.push(new AutoCommand(event, RegExp(regex), cmd)); + this._store.push(AutoCommand(event, RegExp(regex), cmd)); }, this); }, diff --git a/common/content/bookmarks.js b/common/content/bookmarks.js index 8c8d8c10..077c1e8c 100644 --- a/common/content/bookmarks.js +++ b/common/content/bookmarks.js @@ -34,8 +34,8 @@ const Bookmarks = Module("bookmarks", { // Source file: file://~firefox/components/nsTaggingService.js tagging.getTagsForURI(window.makeURI("http://mysterious.bug"), {}); - const Bookmark = new Struct("url", "title", "icon", "keyword", "tags", "id"); - const Keyword = new Struct("keyword", "title", "icon", "url"); + const Bookmark = Struct("url", "title", "icon", "keyword", "tags", "id"); + const Keyword = Struct("keyword", "title", "icon", "url"); Bookmark.defaultValue("icon", function () getFavicon(this.url)); Bookmark.prototype.__defineGetter__("extra", function () [ ["keyword", this.keyword, "Keyword"], @@ -55,7 +55,7 @@ const Bookmarks = Module("bookmarks", { this.__defineGetter__("bookmarks", function () this.load()); this.__defineGetter__("keywords", - function () [new Keyword(k.keyword, k.title, k.icon, k.url) for ([, k] in Iterator(self.bookmarks)) if (k.keyword)]); + function () [Keyword(k.keyword, k.title, k.icon, k.url) for ([, k] in Iterator(self.bookmarks)) if (k.keyword)]); this.__iterator__ = function () (val for ([, val] in Iterator(self.bookmarks))); @@ -65,7 +65,7 @@ const Bookmarks = Module("bookmarks", { let uri = util.newURI(node.uri); let keyword = bookmarksService.getKeywordForBookmark(node.itemId); let tags = tagging.getTagsForURI(uri, {}) || []; - let bmark = new Bookmark(node.uri, node.title, node.icon && node.icon.spec, keyword, tags, node.itemId); + let bmark = Bookmark(node.uri, node.title, node.icon && node.icon.spec, keyword, tags, node.itemId); bookmarks.push(bmark); return bmark; diff --git a/common/content/buffer.js b/common/content/buffer.js index 1e154fe7..d70de3e5 100644 --- a/common/content/buffer.js +++ b/common/content/buffer.js @@ -10,7 +10,7 @@ Components.utils.import("resource://gre/modules/XPCOMUtils.jsm", modules); -const Point = new Struct("x", "y"); +const Point = Struct("x", "y"); /** * A class to manage the primary web content buffer. The name comes diff --git a/common/content/commandline.js b/common/content/commandline.js index 53f2acaa..a29832ad 100644 --- a/common/content/commandline.js +++ b/common/content/commandline.js @@ -121,7 +121,7 @@ const CommandLine = Module("commandline", { ////////////////////// VARIABLES /////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////{{{ - this._completionList = new ItemList("liberator-completions"); + this._completionList = ItemList("liberator-completions"); this._completions = null; this._history = null; diff --git a/common/content/commands.js b/common/content/commands.js index c5c5e9b7..a8eaa669 100644 --- a/common/content/commands.js +++ b/common/content/commands.js @@ -239,7 +239,7 @@ const Command = Class("Command", { /** * @instance commands */ -const ArgType = new Struct("description", "parse"); +const ArgType = Struct("description", "parse"); const Commands = Module("commands", { init: function () { this._exCommands = []; @@ -336,7 +336,7 @@ const Commands = Module("commands", { * @optional */ add: function (names, description, action, extra) { - return this._addCommand(new Command(names, description, action, extra), false); + return this._addCommand(Command(names, description, action, extra), false); }, /** @@ -356,7 +356,7 @@ const Commands = Module("commands", { extra.user = true; description = description || "User defined command"; - return this._addCommand(new Command(names, description, action, extra), replace); + return this._addCommand(Command(names, description, action, extra), replace); }, /** diff --git a/common/content/completion.js b/common/content/completion.js index 8dd2e05a..5dc83621 100644 --- a/common/content/completion.js +++ b/common/content/completion.js @@ -496,7 +496,7 @@ const CompletionContext = Class("CompletionContext", { fork: function fork(name, offset, self, completer) { if (typeof completer == "string") completer = self[completer]; - let context = new CompletionContext(this, name, offset); + let context = CompletionContext(this, name, offset); this.contextList.push(context); if (completer) return completer.apply(self || this, [context].concat(Array.slice(arguments, arguments.callee.length))); @@ -753,7 +753,7 @@ const Completion = Module("completion", { } //}}} }, { - UrlCompleter: new Struct("name", "description", "completer"), + UrlCompleter: Struct("name", "description", "completer"), Javascript: Class("Javascript", { init: function () { diff --git a/common/content/hints.js b/common/content/hints.js index 67095aba..aefec502 100644 --- a/common/content/hints.js +++ b/common/content/hints.js @@ -1022,7 +1022,7 @@ const Hints = Module("hints", { return -1; } })(), - Mode: new Struct("prompt", "action", "tags") + Mode: Struct("prompt", "action", "tags") }, { mappings: function () { var myModes = config.browserModes; diff --git a/common/content/liberator.js b/common/content/liberator.js index c62a4770..4efc132d 100644 --- a/common/content/liberator.js +++ b/common/content/liberator.js @@ -110,7 +110,7 @@ const Liberator = Module("liberator", { return value; } - //const Extension = new Struct("id", "name", "description", "icon", "enabled", "version"); + //const Extension = Struct("id", "name", "description", "icon", "enabled", "version"); return extensions.map(function (e) ({ id: e.id, name: e.name, diff --git a/common/content/mappings.js b/common/content/mappings.js index bbe3fe8c..91f502fe 100644 --- a/common/content/mappings.js +++ b/common/content/mappings.js @@ -201,7 +201,7 @@ const Mappings = Module("mappings", { * @optional */ add: function (modes, keys, description, action, extra) { - this._addMap(new Map(modes, keys, description, action, extra)); + this._addMap(Map(modes, keys, description, action, extra)); }, /** @@ -220,7 +220,7 @@ const Mappings = Module("mappings", { keys = keys.map(this._expandLeader); extra = extra || {}; extra.user = true; - let map = new Map(modes, keys, description || "User defined mapping", action, extra); + let map = Map(modes, keys, description || "User defined mapping", action, extra); // remove all old mappings to this key sequence for (let [, name] in Iterator(map.names)) { diff --git a/common/content/options.js b/common/content/options.js index d6197288..07e5c613 100644 --- a/common/content/options.js +++ b/common/content/options.js @@ -526,7 +526,7 @@ const Options = Module("options", { if (!extraInfo) extraInfo = {}; - let option = new Option(names, description, type, defaultValue, extraInfo); + let option = Option(names, description, type, defaultValue, extraInfo); if (!option) return false; diff --git a/common/content/style.js b/common/content/style.js index 0fa74174..286dbf36 100644 --- a/common/content/style.js +++ b/common/content/style.js @@ -261,7 +261,7 @@ function Highlights(name, store) { if (!(class_ in highlight)) return "Unknown highlight keyword: " + class_; - let style = highlight[key] || new Highlight(key); + let style = highlight[key] || Highlight(key); styles.removeSheet(true, style.selector); if (append) @@ -361,7 +361,7 @@ function Styles(name, store) { '@namespace xul "' + XUL + '";\n' + '@namespace liberator "' + NS.uri + '";\n'; - const Sheet = new Struct("name", "id", "sites", "css", "system", "agent"); + const Sheet = Struct("name", "id", "sites", "css", "system", "agent"); Sheet.prototype.__defineGetter__("fullCSS", function wrapCSS() { let filter = this.sites; let css = this.css;