mirror of
https://github.com/gryf/pentadactyl-pm.git
synced 2025-12-21 08:47:58 +01:00
Remove some redundant uses of "new".
This commit is contained in:
4
HACKING
4
HACKING
@@ -85,6 +85,8 @@ don't use them when the resulting code is hard to read.
|
|||||||
* Prefer lambda-style functions where suitable:
|
* Prefer lambda-style functions where suitable:
|
||||||
Right: list.filter(function (elem) elem.good != elem.BAD);
|
Right: list.filter(function (elem) elem.good != elem.BAD);
|
||||||
Wrong: list.filter(function (elem) { return 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
|
* Anonymous function definitions should be formatted with a space after the
|
||||||
keyword "function". Example: function () {}, not function() {}.
|
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
|
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,
|
* 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)
|
* Prefer // over /* */ comments (exceptions for big comments are usually OK)
|
||||||
Right: if (HACK) // TODO: remove hack
|
Right: if (HACK) // TODO: remove hack
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
/** @scope modules */
|
/** @scope modules */
|
||||||
|
|
||||||
const AutoCommand = new Struct("event", "pattern", "command");
|
const AutoCommand = Struct("event", "pattern", "command");
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @instance autocommands
|
* @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");
|
liberator.log("DEPRECATED: the events list arg to autocommands.add() should be an array of event names");
|
||||||
}
|
}
|
||||||
events.forEach(function (event) {
|
events.forEach(function (event) {
|
||||||
this._store.push(new AutoCommand(event, RegExp(regex), cmd));
|
this._store.push(AutoCommand(event, RegExp(regex), cmd));
|
||||||
}, this);
|
}, this);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
@@ -34,8 +34,8 @@ const Bookmarks = Module("bookmarks", {
|
|||||||
// Source file: file://~firefox/components/nsTaggingService.js
|
// Source file: file://~firefox/components/nsTaggingService.js
|
||||||
tagging.getTagsForURI(window.makeURI("http://mysterious.bug"), {});
|
tagging.getTagsForURI(window.makeURI("http://mysterious.bug"), {});
|
||||||
|
|
||||||
const Bookmark = new Struct("url", "title", "icon", "keyword", "tags", "id");
|
const Bookmark = Struct("url", "title", "icon", "keyword", "tags", "id");
|
||||||
const Keyword = new Struct("keyword", "title", "icon", "url");
|
const Keyword = Struct("keyword", "title", "icon", "url");
|
||||||
Bookmark.defaultValue("icon", function () getFavicon(this.url));
|
Bookmark.defaultValue("icon", function () getFavicon(this.url));
|
||||||
Bookmark.prototype.__defineGetter__("extra", function () [
|
Bookmark.prototype.__defineGetter__("extra", function () [
|
||||||
["keyword", this.keyword, "Keyword"],
|
["keyword", this.keyword, "Keyword"],
|
||||||
@@ -55,7 +55,7 @@ const Bookmarks = Module("bookmarks", {
|
|||||||
this.__defineGetter__("bookmarks", function () this.load());
|
this.__defineGetter__("bookmarks", function () this.load());
|
||||||
|
|
||||||
this.__defineGetter__("keywords",
|
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)));
|
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 uri = util.newURI(node.uri);
|
||||||
let keyword = bookmarksService.getKeywordForBookmark(node.itemId);
|
let keyword = bookmarksService.getKeywordForBookmark(node.itemId);
|
||||||
let tags = tagging.getTagsForURI(uri, {}) || [];
|
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);
|
bookmarks.push(bmark);
|
||||||
return bmark;
|
return bmark;
|
||||||
|
|||||||
@@ -10,7 +10,7 @@
|
|||||||
|
|
||||||
Components.utils.import("resource://gre/modules/XPCOMUtils.jsm", modules);
|
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
|
* A class to manage the primary web content buffer. The name comes
|
||||||
|
|||||||
@@ -121,7 +121,7 @@ const CommandLine = Module("commandline", {
|
|||||||
////////////////////// VARIABLES ///////////////////////////////////////////////
|
////////////////////// VARIABLES ///////////////////////////////////////////////
|
||||||
/////////////////////////////////////////////////////////////////////////////{{{
|
/////////////////////////////////////////////////////////////////////////////{{{
|
||||||
|
|
||||||
this._completionList = new ItemList("liberator-completions");
|
this._completionList = ItemList("liberator-completions");
|
||||||
this._completions = null;
|
this._completions = null;
|
||||||
this._history = null;
|
this._history = null;
|
||||||
|
|
||||||
|
|||||||
@@ -239,7 +239,7 @@ const Command = Class("Command", {
|
|||||||
/**
|
/**
|
||||||
* @instance commands
|
* @instance commands
|
||||||
*/
|
*/
|
||||||
const ArgType = new Struct("description", "parse");
|
const ArgType = Struct("description", "parse");
|
||||||
const Commands = Module("commands", {
|
const Commands = Module("commands", {
|
||||||
init: function () {
|
init: function () {
|
||||||
this._exCommands = [];
|
this._exCommands = [];
|
||||||
@@ -336,7 +336,7 @@ const Commands = Module("commands", {
|
|||||||
* @optional
|
* @optional
|
||||||
*/
|
*/
|
||||||
add: function (names, description, action, extra) {
|
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;
|
extra.user = true;
|
||||||
description = description || "User defined command";
|
description = description || "User defined command";
|
||||||
|
|
||||||
return this._addCommand(new Command(names, description, action, extra), replace);
|
return this._addCommand(Command(names, description, action, extra), replace);
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -496,7 +496,7 @@ const CompletionContext = Class("CompletionContext", {
|
|||||||
fork: function fork(name, offset, self, completer) {
|
fork: function fork(name, offset, self, completer) {
|
||||||
if (typeof completer == "string")
|
if (typeof completer == "string")
|
||||||
completer = self[completer];
|
completer = self[completer];
|
||||||
let context = new CompletionContext(this, name, offset);
|
let context = CompletionContext(this, name, offset);
|
||||||
this.contextList.push(context);
|
this.contextList.push(context);
|
||||||
if (completer)
|
if (completer)
|
||||||
return completer.apply(self || this, [context].concat(Array.slice(arguments, arguments.callee.length)));
|
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", {
|
Javascript: Class("Javascript", {
|
||||||
init: function () {
|
init: function () {
|
||||||
|
|||||||
@@ -1022,7 +1022,7 @@ const Hints = Module("hints", {
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
})(),
|
})(),
|
||||||
Mode: new Struct("prompt", "action", "tags")
|
Mode: Struct("prompt", "action", "tags")
|
||||||
}, {
|
}, {
|
||||||
mappings: function () {
|
mappings: function () {
|
||||||
var myModes = config.browserModes;
|
var myModes = config.browserModes;
|
||||||
|
|||||||
@@ -110,7 +110,7 @@ const Liberator = Module("liberator", {
|
|||||||
return value;
|
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) ({
|
return extensions.map(function (e) ({
|
||||||
id: e.id,
|
id: e.id,
|
||||||
name: e.name,
|
name: e.name,
|
||||||
|
|||||||
@@ -201,7 +201,7 @@ const Mappings = Module("mappings", {
|
|||||||
* @optional
|
* @optional
|
||||||
*/
|
*/
|
||||||
add: function (modes, keys, description, action, extra) {
|
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);
|
keys = keys.map(this._expandLeader);
|
||||||
extra = extra || {};
|
extra = extra || {};
|
||||||
extra.user = true;
|
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
|
// remove all old mappings to this key sequence
|
||||||
for (let [, name] in Iterator(map.names)) {
|
for (let [, name] in Iterator(map.names)) {
|
||||||
|
|||||||
@@ -526,7 +526,7 @@ const Options = Module("options", {
|
|||||||
if (!extraInfo)
|
if (!extraInfo)
|
||||||
extraInfo = {};
|
extraInfo = {};
|
||||||
|
|
||||||
let option = new Option(names, description, type, defaultValue, extraInfo);
|
let option = Option(names, description, type, defaultValue, extraInfo);
|
||||||
|
|
||||||
if (!option)
|
if (!option)
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -261,7 +261,7 @@ function Highlights(name, store) {
|
|||||||
if (!(class_ in highlight))
|
if (!(class_ in highlight))
|
||||||
return "Unknown highlight keyword: " + class_;
|
return "Unknown highlight keyword: " + class_;
|
||||||
|
|
||||||
let style = highlight[key] || new Highlight(key);
|
let style = highlight[key] || Highlight(key);
|
||||||
styles.removeSheet(true, style.selector);
|
styles.removeSheet(true, style.selector);
|
||||||
|
|
||||||
if (append)
|
if (append)
|
||||||
@@ -361,7 +361,7 @@ function Styles(name, store) {
|
|||||||
'@namespace xul "' + XUL + '";\n' +
|
'@namespace xul "' + XUL + '";\n' +
|
||||||
'@namespace liberator "' + NS.uri + '";\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() {
|
Sheet.prototype.__defineGetter__("fullCSS", function wrapCSS() {
|
||||||
let filter = this.sites;
|
let filter = this.sites;
|
||||||
let css = this.css;
|
let css = this.css;
|
||||||
|
|||||||
Reference in New Issue
Block a user