Reasons
- V8 optimizations
- Better minification and obfuscation
- Harder deobfuscation
Example 1
class Foo {
constructor() {
this.x = 1;
}
get x() {
return this.x;
}
}
console.log(new Foo().x);
function Foo_constructor() {
/* or just return { x: 1 } */
var self = {};
self.x = 1;
return self;
}
function Foo_get_x(self) {
return self.x;
}
console.log(Foo_get_x(Foo_constructor()));
Example 2
class Foo {
getHelloString() {
return 'hello';
}
}
class Bar extends Foo {
getHelloString() {
return super.getHelloString() + ' world';
}
}
console.log(new Bar().getHelloString());
function Foo_getHelloString(self) {
return 'hello';
}
function Bar_getHelloString(self) {
return Foo_getHelloString(self) + ' world';
}
console.log(Bar_getHelloString({}));
Reasons
Example 1
Example 2