简体   繁体   English

未捕获的TypeError:无法读取未定义的属性“ render”

[英]Uncaught TypeError: Cannot read property 'render' of undefined

i'm still learning how to do stuffs in a canvas like this one. 我仍在学习如何在这样的画布上做东西。 Rendering a rectangle object in ay coordinates. 在y坐标中渲染矩形对象。

function initCanvas(){
var ctx = document.getElementById('canvas').getContext('2d');
var cW = ctx.canvas.width, cH = ctx.canvas.height;
var y = 0, x = 0;

function rectObj(){
    this.x = 0, this.y = 0;
    this.render = function(ctx, lx, ly, lw, lh, clr){
        ctx.fillStyle = clr;
        ctx.fillRect(lx, ly, lw, lh);
    }
}

var a = rectObj();

function animate(){
    ctx.clearRect(0,0, cW, cH);
    a.render(ctx, 0, a.y, 50, 50, "blue");
    a.y++;
}
var animateInterval = setInterval(animate, 30);

}window.addEventListener('load', function(event){ initCanvas(); });

您应该使用new运算符调用该函数:

var a = new rectObj();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 未捕获的TypeError:无法读取未定义的属性“ render” - Uncaught TypeError: Cannot read property ‘render’ of undefined 未捕获的TypeError:无法在Constructor.render中读取未定义的属性“name” - Uncaught TypeError: Cannot read property 'name' of undefined at Constructor.render 未捕获到的TypeError:无法读取ReactJs中{Component} .render上未定义的属性“ map” - Uncaught TypeError: Cannot read property 'map' of undefined at {Component}.render in ReactJs 未捕获的TypeError:无法读取未定义的属性“未定义” - Uncaught TypeError: Cannot read property 'undefined' of undefined 未捕获的类型错误:无法设置未定义的属性“渲染” - Uncaught TypeError: Cannot Set Property 'Render' of Undefined 未捕获的TypeError:无法读取未定义的属性“ on” - Uncaught TypeError: Cannot read property 'on' of undefined 未捕获的类型错误:无法读取未定义的属性“scrollHeight” - Uncaught TypeError: Cannot read property 'scrollHeight' of undefined 未捕获的TypeError:无法读取未定义的属性“ add” - Uncaught TypeError: Cannot read property 'add' of undefined 未捕获的TypeError:无法读取未定义的属性'GetLatdlngd' - Uncaught TypeError: Cannot read property 'GetLatdlngd' of undefined 未捕获的TypeError:无法读取未定义的属性“获取” - Uncaught TypeError: Cannot read property 'fetch' of undefined
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM