When I run the code below in chrome,
I got error “Uncaught ReferenceError: detail is not defined”;
I try to define object shape with the name hamburgers and then to create the hamburger.
what is wrong in the code
Many thanks.
function Hamburger(x,y,w,h){
this.x = x;
this.y = y;
this.w = w;
this.h = h;
}
var shape = {
hamburgers: [],
};
function drawshape(x, y, w, h) {
alert(x+' '+y+' '+w+' '+h);
}
shape.details =
[
{
"detail" : 0,
"hamburgers" : [{"x" : -290, "y" : -140,"w" : -290, "h" : -140}]
}
];
i = 0;
shape.hamburgers.push(new Hamburger(detail.hamburgers[i].x, detail.hamburgers[i].y,detail.hamburgers[i].w,detail.hamburgers[i].h));
for(var i=0;i<shape.hamburgers.length;i++) {
var hamburger = shape.hamburgers[i];
var x = hamburger.x;
var y = hamburger.y;
var w = hamburger.w;
var h = hamburger.h;
drawshape(x, y, w, h);
}
detailisn’t defined because you are actually trying to findshape.details[0]. Definingdetailas that array item fixes it.http://jsfiddle.net/EaPr7/