Javascript JS无法调用null的drawImage方法

Javascript JS无法调用null的drawImage方法,javascript,html,canvas,Javascript,Html,Canvas,我有一份小档案 /* WaterBall API notification model by Makerimages*/ function WBNotification(x,y,icon,text) { this.background="/WBGraphics/WBNotification.png"; this.x=x; this.y=y; this.icon=icon; this.text=text; this.draw=function() { var canvas = doc

我有一份小档案

/* WaterBall API notification model by Makerimages*/
function WBNotification(x,y,icon,text)
{
this.background="/WBGraphics/WBNotification.png";
this.x=x;
this.y=y;
this.icon=icon;
this.text=text;






this.draw=function()
{

var canvas = document.createElement('canvas');
canvas.id="WBNotificationArea";
canvas.width=88;
canvas.height =43;
document.body.appendChild(canvas);
cvs=document.getElementById("WBNotificationArea");
var context=cvs.getContext();
context.drawImage(this.background,this.x,this.y);
}
 return this;
}
我是这样用的

site=new waterContainer();
site.notifications[0]=new WBNotification(10,10,null,"hello there!");
site.notifications[0].draw()

一切正常,但this.draw()表示(在chrome的脚本读取内容中)它不能调用null的drawImage方法,我如何修复它?

您需要将字符串
“2d”
传递到
getContext()


如果提供的上下文类型不可用,函数将返回
null

您需要将字符串
“2d”
传递到
getContext()


如果提供的上下文类型不可用,函数将返回
null

您需要将字符串
“2d”
传递到
getContext()


如果提供的上下文类型不可用,函数将返回
null

您需要将字符串
“2d”
传递到
getContext()



如果提供的上下文类型不可用,函数将返回null。

如果不支持contextId值,getContext方法将返回null。
如果不支持contextId值,getContext方法将返回null。
如果不支持contextId值,getContext方法将返回null支持。
如果不支持contextId值,则getContext方法返回null。
这会使它说Uncaught TypeError Type Error在您的第二段代码中这是什么?不应该是WBNotification.prototype吗?你指的是哪一行????是回路线吗?如果我将其设置为returning thw WbNotification.prototype,它会在站点中显示。。。文件对象#没有方法“Draw”使其说uncaughttypeerror Type error在第二段代码中这是什么?不应该是WBNotification.prototype吗?你指的是哪一行????是回路线吗?如果我将其设置为returning thw WbNotification.prototype,它会在站点中显示。。。文件对象#没有方法“Draw”使其说uncaughttypeerror Type error在第二段代码中这是什么?不应该是WBNotification.prototype吗?你指的是哪一行????是回路线吗?如果我将其设置为returning thw WbNotification.prototype,它会在站点中显示。。。文件对象#没有方法“Draw”使其说uncaughttypeerror Type error在第二段代码中这是什么?不应该是WBNotification.prototype吗?你指的是哪一行????是回路线吗?如果我将其设置为returning thw WbNotification.prototype,它会在站点中显示。。。对象#没有“绘制”方法的文件