Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DIfference between objects in console on chrome developer tools

When I print one of my objects (created via ajax calls) to the console I am getting back:

Object
discreet: Array[2]
range: Array[2]
__proto__: Object

But when I manually create the object I am correctly getting back:

Object {range: Array[2], discreet: Array[2]}
discreet: Array[2]
range: Array[2]
__proto__: Object

Could someone explain to me the difference between these two objects, and why I am unable to access the properties of the first object?

Edit: The first object is being created by:

var obj = {}

$http.get('/discreet').then( function(data) { obj.discreet = data } );
$http.get('/range').then( function(data) { obj.range = data } );

print(obj);

The second I am hand crafting:

var obj = { range: [1,2], discreet: [1,2] }
print(obj);
like image 275
Alan Pledger Avatar asked Feb 03 '26 01:02

Alan Pledger


1 Answers

The first one is simply being printed before the xhr response has returned, so the object is empty at the time it is logged.

The second one is logged after it has been populated.

like image 154
gray state is coming Avatar answered Feb 04 '26 14:02

gray state is coming