function A() { this.val = "Error"; (function() { this.val = "Success"; })(); } function B() { this.val = "Error"; (() => { this.val = "Success"; })(); } var a = new A(); var b = new B(); a.val // "Error" b.val // "Success"