0

Does eval() run in strict mode in methods?

class A { b() {eval("with(this) { 1 } ")} }
new A().b()
// strict mode error

But not in functions?

function b() {eval("with(this) { 1 }")}
b()
> 1
Sam Goto
  • 475
  • 6
  • 11
  • Sure `eval` runs. But `with` is not allowed in there. Have you actually looked at the error message? – Bergi Sep 06 '17 at 19:55

1 Answers1

1

This is explicitly stated in docs MDN, ES2017.

The bodies of class declarations and class expressions are executed in strict mode i.e. constructor, static and prototype methods, getter and setter functions are executed in strict mode.

Yury Tarabanko
  • 44,270
  • 9
  • 84
  • 98