Javascript HTML5矩形打印数组错误

Javascript HTML5矩形打印数组错误,javascript,html,canvas,html5-canvas,Javascript,Html,Canvas,Html5 Canvas,所以我花了2个小时来困惑自己,为什么这行不通,我遵循了上面问题中的所有代码,但它仍然行不通,我做错了什么 我加了一个方块,以确保它能到达那条线,并能正常工作 这似乎是形状对象中的一个简单输入错误: function Shape(a,b,w,h,fill){ this.x = a; /// change to this.x this.y = b; /// change to this.y this.w = w; this.h = h; this.fil

所以我花了2个小时来困惑自己,为什么这行不通,我遵循了上面问题中的所有代码,但它仍然行不通,我做错了什么

我加了一个方块,以确保它能到达那条线,并能正常工作


这似乎是
形状
对象中的一个简单输入错误:

function Shape(a,b,w,h,fill){

    this.x = a; /// change to this.x
    this.y = b; /// change to this.y

    this.w = w;
    this.h = h;
    this.fill = fill;
}

或者,您也可以通过提供适当的变量名来降低此类键入错误的风险,例如:

function Shape(x, y, w, h, fill){

    this.x = x;  /// now we see the link more clearly
    this.y = y;

    this.w = w;
    this.h = h;
    this.fill = fill;
}

非常感谢!深夜头累了!!javascript也是新手,所以要习惯它!再次感谢你,伙计!
function Shape(x, y, w, h, fill){

    this.x = x;  /// now we see the link more clearly
    this.y = y;

    this.w = w;
    this.h = h;
    this.fill = fill;
}