views:

39

answers:

2

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?

+1  A: 

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 = ....

Brian Campbell
+1  A: 

change

var pauses = new Array();

to

this.pauses = new Array();

or, better

this.pauses = [];
Triptych
whats the difference between new Array() and []?
Tyler Gillies