2D Grid class in javascript