on below query me going , clarify many doubts. far, read have class in js through function statements, , json notation hold object values. so, in below code
- how write testdata variable holds shape values
how initialize shape objects testdata. may able create object assigning each member
var obj = { x: testdata[i].x, y: testdata[i].y, ... };
is proper way, or can use constructors described here
var testdata = [ {}, {} ] //shape class var shape = function(x, y, w, h) { this.x = x; this.y = y; this.w = w; this.h = h; this.calculatearea = function() { alert("area.."); }; func test() { var arr = []; (var i=0,l=testdata.length; i<l; i++) { var s = testdata[i]; var obj = // how construct shape object here through constructor }; arr.push(obj); }
you can construct new object (a shape
, in case) new
keyword. use:
var obj = new shape(testdata[i].x, testdata[i].y, testdata[i].w, testdata[i].h);
Comments
Post a Comment