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.pull/4601/head
parent
c1ef12b8da
commit
8efc87f33a
|
@ -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, ''];
|
||||
|
|
Loading…
Reference in New Issue