Javascript object functions help

Hi all,

I'm new to javascript and I have no idea what I'm doing wrong. I have created a mazeObject fine, and would like to hold an array of mazeTile inside it, but when I try to define the objects in the array it creates them as a function rather than as the object.

mazeObject and instancing:
var mazeObject = function () {

    var constructor = function mazeObject(width, height) {
        var width;
        var height;
        var tiles;

        this.width = width;
        this.height = height;

        this.resize = function (x, y) {
            this.tiles = [];

            // Creates all lines:
            for (var i = 0; i < x; i++) {

                // Creates an empty line
                this.tiles.push([]);

                // Adds cols to the empty line:
                this.tiles[i].push(new Array(y));
            }

            this.clear()
        }

        this.clear = function () {
            for (var i = 0; i < this.width; i++)
                for (var j = 0; j < this.height; j++) {
                    this.tiles[i][j] = new mazeTile();
                }
        }

        this.getTile = function (x, y) {
            return this.tiles[x - 1, y - 1];
        };

        this.setTile = function (x, y, value) {
            this.tiles[x - 1, y - 1].contents = value;

        }

        // Initialize the tiles
        this.resize(width, height);
        this.setTile(1, 1, tcDiamondDoor);
    };

    return constructor;
}();
var maze = new mazeObject(7, 5);

Open in new window


mazeTile (instancing in mazeObject.clear)
var mazeTile = function () {

    var constructor = function mazeTile() {
        var topWall = twNone;
        var leftWall = twNone;
        var otherWall = twoNone;
        var contents = tcNone;

        this.getContents = function () {
            return contents;
        }

    }

    return constructor;
}

Open in new window


When maze.clear gets called and it creates the instance of all the mazetile objects, those tiles are of prototype function(), while the maze itself is something different.

And later when I try to use/read the tiles javascript crashes with no error (tried with just .contents or a function getcontents):
            if (tileRectContents[maze.getTile(i, j).contents] != tcNone)
            {
                drawImage(ctx, imgSpriteTile, tileRectContents[maze.getTile(i, j).getContents()], targetRect);
            }

Open in new window


Any help would be appreciated as google has not been helpful
Primoz IvancicAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Primoz IvancicAuthor Commented:
turns out i was missing a () after defining my function object.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.