Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Strange javascript object init?

I recently came across this variable initialization in a WebGL tutorial:

var mouse = { x: 0, y: 0 }, INTERSECTED;

I've never seen this format. I understand it's creating an object with an x and y property, but how is INTERSECTED related to the variable/object?

Thanks!

like image 208
rob-gordon Avatar asked Dec 07 '22 10:12

rob-gordon


1 Answers

The line is simply declaring two variables (mouse and INTERSECTED), and initializing mouse to { x: 0, y: 0}.

INTERSECTED is not necessarily related to mouse, though clear code should only declare multiple variables together if they are highly related (even then, many prefer to declare every variable on a separate line).

like image 173
Cameron Avatar answered Dec 25 '22 19:12

Cameron