开发者

javascript: how to call variable instance inside variable?

I am trying to make something like this:

var Test = 
{
    A:function()
    {
     array = new Array();
     arra开发者_如何学编程y[0] = new Array("1","2","3");
     array[1] = new Array("Name","Age","blabla");
    },

    B: function()
    {
      var c = new this.A();
      alert(c);   //output:: object Object
      alert(c.array[1]); // output:: undefined
      alert(c.array[1][0]); // output undefined
    }    
}

how can i get alerted for example alert(c.array[1][0]) with output "Name". usually in other languages its possible to use methodes from inherited classes but in javascript. i think(hope) it's possible, but how?

Painkiller


You'd have to change A:

A:function()
{
 this.array = new Array();
 this.array[0] = new Array("1","2","3");
 this.array[1] = new Array("Name","Age","blabla");
},

If you do change it, you'd be better to do this:

A:function()
{
  this.array = [ [ "1", "2", "3" ], [ "Name", "Age", "blabla" ] ];
},

The "Array" constructor is a pretty bad API design and should be avoided.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜