Looking at this code it should produce output "TEST1"+"TEST2" however I get "TEST2" twice:
function TEST1(){
var __construct = function () { this.box = { test_ : function () {console.log('TEST1')} }}
__construct()
}
TEST1.prototype = {t: function(){ return box.test_()} }
function TEST2(){
var __construct = function () { this.box = { test_ : function () {console.log('TEST2')} }}
__construct()
}
TEST2.prototype = {t: function(){ return box.test_()}}
var t1 = new TEST1()
var t2 = new TEST2()
t1.t()
t2.t()
If I rename "box" in second function I get correct output:
function TEST2(){
var __construct = function () { this.box_ = { test_ : function () {console.log('TEST2')} }}
__construct()
}
TEST2.prototype = {t: function(){ return box_.test_()}}
Why is there this what appears a variable isolation issue?