I am trying to use conditional logic inside a JavaScript class constructor.
Context: I am creating a 2d grid in a double for loop, with each cell having a property of North, South, East, and West. To keep in bounds of the 2d Grid, I am trying to only create a cell that has N,S,E properties, if that cell lay on the edge with col equal to 0.
For a 4x4 grid, I try to build this item and I keep getting the error, "Uncaught SyntaxError: Unexpected token '!='". So I believe the issue is just with my poor knowledge of Javascript Syntax. Any Suggestions?
class Cell {
constructor(row,col){
this.visited = false;
this.row = row;
this.col = col;
this.edges = {
if(row!=0){
north:1,
},
if(row!=3)){
south:1,
},
if(col!=0)){
west:1,
},
if(col!=3)){
east:1,
},
}
}
}