0

I'm new at Javascript, starting for the first time. I am trying to use Jasmine to test objects and their methods. I have the following code:

function Monkey(x, y) {
    this.x = x;
    this.y = y;

    this.goteam = new function () {
        return x;
    };
}

describe("Cool", function () {
    it("should work", function () {
        var monkey = new Monkey(1, 2);
        var value = monkey.goteam();
        expect(value).toBe(1);
    });
});

The test Cool it should work gives me "[object Object] is not a function on the line value = monkey.goteam(); I have spent an hour reading tutorials and searching, but have come up dry no matter what I try. Any help is much appreciated.

1
  • goteam should just be a function, not new function() ... Pro tip: just try stuff out in the console before bothering to write a test; it excludes an entire class of issues. Creating a new Monkey(...) and looking at it would have helped clue you in. Commented Apr 4, 2015 at 17:52

1 Answer 1

1

this.goTeam should be declared as a function, not a new function. The new keyword is not necessary here.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.