Forums > Javascript

[JS] Global object

December 18, 2013 | 8:06 am

Hello !

i did some observations on how the [ Global ] object behave in terms of efficiency .
Ive been not wondering why its slow when it comes to any operations on its instance .
Like changing the value in separate [JS] instance will reflect in the other one that is referencing the same Global object . This is incredibly helpful idea . but slow .
or not ?
I found unexpected behavior that breaks all my understanding on how object references are really working . or maybe in this particular case .

As said, working on a Global object is really slow .

main js :

var data = new Global("share") ;
	data.value = 9 ;

other js :

var other = new Global("share") ;

for(var i = 0 ; i < 100000 ; i++){
	other.value = i ;
}

But when you create a separate reference to it in another [JS] instance …

main js :

var data = new Global("share") ;
	data.value = 9 ;

other js :

var other = new Global("share") ;

var shared = {} ;
shared = other ;

for(var i = 0 ; i < 100000 ; i++){
	shared.value = i ;
}

its efficiency seems to be exactly the same as operating on local JS object itself . Also we need to take a note that it is a reference only , so it will reflect any changes in other [JS] instance without any additional lag that is introduced by Global object .
Why is that ? I thought that initialization of our Global object on a variable creates its reference anyway . Acts slow . But creating another reference removes any lags ? Or im wrong ?


Viewing 1 post (of 1 total)