A few questions surrounding javascript arrays, in-built methods -


![enter image description here][1]

function setfood () {    var empty = [];    (var x=0; x<grid.width; x++) {       (var y=0; y>grid.height; y++) {            if (grid.get(x,y) === empty) {           empty.push({x:x, y:y});        }     }   } }; 

i watched video on youtube making snake game , came across whilst creator making function.

now have few questions want know answer can keep learning.

first: .get method? when searched it gave me results on jquery ever referenced jquery library anywhere javascript code? empty? pre programmed term javascript means same thing 0 or ``null? , lastly. why creator using brackets within push method? push empty array? , x:x , y:y mean?

i sorry questions. it's not have other people turn coding questions except coding community itself.

empty array, declared in var empty = []; empty, on other hand, variable. javascript case-sensitive it's not alias of empty[] array. it's common practice define constants in upper case it's clear are. variable contains value signifies empty cell.

empty.push({x:x, y:y}); pushing javascript object {x:x, y:y} on array. {} javascript syntax object. 1 contains x , y properties retrieved get() method of grid.

in case grid javascript object declared elsewhere in code. since code's not here can assume grid object holds status of grid on snake moving, , get() method retrieving status of element in grid.


Comments

Popular posts from this blog

qt - Using float or double for own QML classes -

Create Outlook appointment via C# .Net -

ios - Swift Array Resetting Itself -