我只是为我的画布设置了一个小框架,我没有经常使用 Prototype,但它似乎非常棒,只是有一个小问题,create
函数没有从new
函数继承宽度和高度,我该怎么做?代码:
function CtxCanvas() {
this.fps = undefined;
this.width = undefined;
this.height = undefined;
}
CtxCanvas.prototype = {
constructor: CtxCanvas,
new: function(fps, width, height) {
this.fps = fps;
this.width = width;
this.height = height;
},
create: function() {
var df = document.createDocumentFragment()
, canvasElement = document.createElement('canvas');
canvasElement.width = this.width;
canvasElement.height = this.height;
df.appendChild(canvasElement);
document.getElementsByTagName('body')[0].appendChild(df);
return canvasElement.getContext('2d');
}
}
var ctx = new CtxCanvas(30, 1000, 1000).create();