Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: lib/utils.js

Issue 29371763: Issue 4795 - Use modern JavaScript syntax (Closed)
Patch Set: Addressed some more feedback Created Jan. 18, 2017, 11:44 a.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « lib/url.js ('k') | lib/whitelisting.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/utils.js
diff --git a/lib/utils.js b/lib/utils.js
index e965cad717e4cb7f2c19a8181a4edbebf322f14c..9361039f8137f85bb5fe4f7fbf43590531c9a657 100644
--- a/lib/utils.js
+++ b/lib/utils.js
@@ -15,19 +15,21 @@
* along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
*/
-var Utils = exports.Utils = {
+"use strict";
+
+let Utils = exports.Utils = {
systemPrincipal: null,
- getString: function(id)
+ getString(id)
{
return ext.i18n.getMessage("global_" + id);
},
- runAsync: function(callback)
+ runAsync(callback)
{
if (document.readyState == "loading")
{
// Make sure to not run asynchronous actions before all
// scripts loaded. This caused issues on Opera in the past.
- let onDOMContentLoaded = function()
+ let onDOMContentLoaded = () =>
{
document.removeEventListener("DOMContentLoaded", onDOMContentLoaded);
callback();
@@ -41,40 +43,38 @@ var Utils = exports.Utils = {
},
get appLocale()
{
- var locale = ext.i18n.getMessage("@@ui_locale").replace(/_/g, "-");
+ let locale = ext.i18n.getMessage("@@ui_locale").replace(/_/g, "-");
Object.defineProperty(this, "appLocale", {value: locale, enumerable: true});
return this.appLocale;
},
- generateChecksum: function(lines)
+ generateChecksum(lines)
{
// We cannot calculate MD5 checksums yet :-(
return null;
},
- checkLocalePrefixMatch: function(prefixes)
+ checkLocalePrefixMatch(prefixes)
{
if (!prefixes)
return null;
- var list = prefixes.split(",");
- for (var i = 0; i < list.length; i++)
- if (new RegExp("^" + list[i] + "\\b").test(this.appLocale))
- return list[i];
+ for (let prefix of prefixes.split(","))
+ if (new RegExp("^" + prefix + "\\b").test(this.appLocale))
+ return prefix;
return null;
},
- chooseFilterSubscription: function(subscriptions)
+ chooseFilterSubscription(subscriptions)
{
- var selectedItem = null;
- var selectedPrefix = null;
- var matchCount = 0;
- for (var i = 0; i < subscriptions.length; i++)
+ let selectedItem = null;
+ let selectedPrefix = null;
+ let matchCount = 0;
+ for (let subscription of subscriptions)
{
- var subscription = subscriptions[i];
if (!selectedItem)
selectedItem = subscription;
- var prefix = require("utils").Utils.checkLocalePrefixMatch(subscription.getAttribute("prefixes"));
+ let prefix = Utils.checkLocalePrefixMatch(subscription.getAttribute("prefixes"));
if (prefix)
{
if (!selectedPrefix || selectedPrefix.length < prefix.length)
@@ -102,14 +102,13 @@ var Utils = exports.Utils = {
return selectedItem;
},
- getDocLink: function(linkID)
+ getDocLink(linkID)
{
- var Prefs = require("prefs").Prefs;
- var docLink = Prefs.documentation_link;
+ let docLink = require("prefs").Prefs.documentation_link;
return docLink.replace(/%LINK%/g, linkID).replace(/%LANG%/g, Utils.appLocale);
},
- yield: function()
+ yield()
{
}
};
« no previous file with comments | « lib/url.js ('k') | lib/whitelisting.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld