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

Unified Diff: ext/background.js

Issue 29371763: Issue 4795 - Use modern JavaScript syntax (Closed)
Patch Set: Fix scoping regression Created Jan. 16, 2017, 9:12 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
Index: ext/background.js
diff --git a/ext/background.js b/ext/background.js
index f6ce8ce075bae22f0569a1cdd741ee29646ba580..d8f67beff947da4193fdddaa5dd1a655ae5a4446 100644
--- a/ext/background.js
+++ b/ext/background.js
@@ -15,55 +15,56 @@
* along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
*/
-(function()
+"use strict";
+
{
- var nonEmptyPageMaps = Object.create(null);
- var pageMapCounter = 0;
+ let nonEmptyPageMaps = Object.create(null);
Sebastian Noack 2017/01/16 14:47:40 In "modern JavaScript" you wouldn't (mis)use objec
kzar 2017/01/16 14:59:07 Good point, but would you mind if we left that for
Sebastian Noack 2017/01/16 15:35:54 Acknowledged.
+ let pageMapCounter = 0;
- var PageMap = ext.PageMap = function()
+ let PageMap = ext.PageMap = function()
{
this._map = Object.create(null);
this._id = ++pageMapCounter;
};
PageMap.prototype = {
- _delete: function(id)
+ _delete(id)
{
delete this._map[id];
if (Object.keys(this._map).length == 0)
delete nonEmptyPageMaps[this._id];
},
- keys: function()
+ keys()
{
return Object.keys(this._map).map(ext.getPage);
},
- get: function(page)
+ get(page)
{
return this._map[page.id];
},
- set: function(page, value)
+ set(page, value)
{
this._map[page.id] = value;
nonEmptyPageMaps[this._id] = this;
},
- has: function(page)
+ has(page)
{
return page.id in this._map;
},
- clear: function()
+ clear()
{
- for (var id in this._map)
+ for (let id in this._map)
this._delete(id);
},
- delete: function(page)
+ delete(page)
{
this._delete(page.id);
}
};
- ext._removeFromAllPageMaps = function(pageId)
+ ext._removeFromAllPageMaps = pageId =>
{
- for (var pageMapId in nonEmptyPageMaps)
+ for (let pageMapId in nonEmptyPageMaps)
nonEmptyPageMaps[pageMapId]._delete(pageId);
};
-})();
+}

Powered by Google App Engine
This is Rietveld