From 8efc87f33a88cb1dec4b8e88ca2193e3eb63a225 Mon Sep 17 00:00:00 2001 From: Richard Hansen Date: Fri, 29 Jan 2021 02:55:02 -0500 Subject: [PATCH] AttributeManager: Fix bogus `this` during attribute removal Before this commit, the callback passed to `.map()` during attribute removal was a normal function, not an arrow function. This meant that the value of `this` in the function body depended on how the callback was invoked. In this case, the callback was invoked without any explicit context (it was not called as a method, nor was it called via `.call()`, `.apply()`, or `.bind()`). Without any explicit context, the value of `this` depends on strict mode. Currently the function is in sloppy mode, so `this` refers to the "global this" object (a.k.a., `window`). It doesn't make sense for the callback to reference `window.author`, so I'm assuming the previous behavior was a bug. Now the function is an arrow function, so the value of `this` comes from the enclosing lexical context, which in this case is the AttributeManager object. I believe that was the original intention. --- src/static/js/AttributeManager.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/static/js/AttributeManager.js b/src/static/js/AttributeManager.js index c1257a9bc..32df255da 100644 --- a/src/static/js/AttributeManager.js +++ b/src/static/js/AttributeManager.js @@ -349,7 +349,7 @@ AttributeManager.prototype = _(AttributeManager.prototype).extend({ const hasMarker = this.lineHasMarker(lineNum); let found = false; - const attribs = _(this.getAttributesOnLine(lineNum)).map(function (attrib) { + const attribs = _(this.getAttributesOnLine(lineNum)).map((attrib) => { if (attrib[0] === attributeName && (!attributeValue || attrib[0] === attributeValue)) { found = true; return [attributeName, ''];