I am wondering if i can get the object property using array. I am getting ‘undefine’ value for this.label[i].xOffset. Any suggestions?
function label() {
var lbl = this;
lbl.rText;
lbl.precision =1;
lbl.prefix = '';
lbl.suffix = '';
lbl.xOffset = this.width/2;
lbl.yOffset = this.height*82/100
}
this.NoOfneedles=2;
if (this.NoOfneedles > 1) {
this.label = [];
for (i=0;i<this.NoOfneedles;i++) {
this.label[i]=new label();
alert("label xOffset:"+this.label[i]+this.label[i].xOffset);
}
}
Your
labelobject has nowidthandheightproperties and already others said you that but if you just definewidthandheightinside your constructor then it could be written as followsRemember this refers to current object and you are using
this.width/2;inside your constructor sothis=Labeland I’ve changed thelabeltoLabeland outside the constructor/in global scopethisrefers to default global objectwindowand in the global scopethis.someVarandsomeVaris same becausewindowis the default global object and by default we don’t need to use it so we can usedocument.getElementbyIdinstrad ofwindow.document.getElementbyId.