1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2025-12-21 07:37:58 +01:00

Remove some redundant uses of "new".

This commit is contained in:
Doug Kearns
2009-11-14 23:07:56 +11:00
parent 90410f2bf6
commit 52749d6722
12 changed files with 23 additions and 21 deletions

View File

@@ -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

View File

@@ -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);
},

View File

@@ -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;

View File

@@ -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

View File

@@ -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;

View File

@@ -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);
},
/**

View File

@@ -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 () {

View File

@@ -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;

View File

@@ -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,

View File

@@ -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)) {

View File

@@ -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;

View File

@@ -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;