3 ms·
Here's a fun one about `this` that you might not know. When running `eval`, `this` refers to the `this` in the calling context. Unless you alias the method. The
by vkjv 9y ago
Here's a fun one about `this` that you might not know. When running `eval`, `this` refers to the `this` in the calling context. Unless you alias the method. Then it refers to the global context.
class Test {
eval() {
return eval('this');
}
aliasEval() {
const e = eval;
return e('this');
}
}
const test = new Test();
assert.equal(test.eval(), test);
assert.equal(test.aliasEval(), global);