0

I'm trying to create a javascript object that can call other methods within itself. However, I'm running into a weird problem that I just can't seem to figure out.

I have the following code

myObjectDef = function() {
    this.init = function() {
        //do some stuff
        this.doSecondInit();
    }
    this.doSecondInit = function() {
        //do some more stuff
    }
}

myObject = new myObjectDef();
myObject.init();

I am getting an error that states "Message: Object doesn't support this property or method". And it ends at this.doSecondInit();. I can't quite figure out why it's doing this. My code runs great up to the call to the second method. How do I make this work?

1
  • 1
    Your code looks OK and works fine for me: jsfiddle.net/vdVE8 - maybe you'll need to show the missing bits. Commented Mar 6, 2012 at 0:26

1 Answer 1

3

There's an extra set of parenthesis here:

this.doSecondInit() = function() {

You can't assign to the result of a function call, let alone to the result of a function that doesn't even exist.

After your edit, your thing seems to work fine:

http://jsfiddle.net/nabVN/

You sure you didn't have the same typo in your actual code? Better start getting used to not putting that () after every function call, which is probably a bad habit carried over from languages where functions aren't values.

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

1 Comment

Looks like I'm going to need to look at my code more carefully. It's definitely not working for me and I definitely don't have the first set of parenthesis. I'm sure there's something else that I'm overlooking at this point.

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.