google / google/closure-compiler
Static `this` is undefined during recursive call
Open
- Dominant language
- JavaScript
- Stars
- 7.7k
- Forks
- 1.2k
- Avg merge
- 2d 12h
- Merged PRs (30d)
- 6
Description
While using `this` in a static class method to recursively call itself works in the browser, it does not work with compiled code:
```javascript
static buildTagCache(node, idCache) {
if (!node || (node.nodeType !== 1)) return; // not an element node
var nn = node.nodeName;
if (nn === 'point' || nn === 'link') {
// do some stuff
}
// search down
util.do4children(node, n => {
this.buildTagCache(n, idCache);
});
}
```
has an `undefined` `this` at the child call.
_Originally posted by @ray007 in https://github.com/google/closure-compiler/issues/3553#issuecomment-590834733_
Contributor guide
Assessment
This issue has not been assessed yet.