1

Hi currently I'm trying to get following snippet of code to work:

function Entry() {
    var pauses = new Array();
}

Entry.prototype = {
   AddElement: function(aParameter) {
      this.pauses.push(aParameter);
   }
}

Unfortunately this code fails with following error in Safari if I try to call AddElement("Test");

TypeError: Result of expression 'this.pauses' [undefined] is not an object. Does anybody know why?

2 Answers 2

1

In your code, pauses is a local variable within the Entry() function, not a member on the object constructed by it.

You want to replace var pauses = ... with this.pauses = ....

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

Comments

1

change

var pauses = new Array();

to

this.pauses = new Array();

or, better

this.pauses = [];

1 Comment

whats the difference between new Array() and []?

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.