我已定义var canvas = new fabric.Canvas('tcanvas')
,但在创建函数期间,我收到此错误:TypeError: this.canvas is undefined
。这是我的代码:
if (mood === 'hline') {
canvas.freeDrawingBrush = vLinePatternBrush;
}
var vLinePatternBrush = new fabric.PatternBrush(canvas);
vLinePatternBrush.getPatternSrc = function() {
var patternCanvas = canvas;
patternCanvas.width = patternCanvas.height = 10;
var ctx = patternCanvas.getContext('2d');
ctx.strokeStyle = $("#drawing-color").val();
ctx.lineWidth = 5;
ctx.beginPath();
ctx.moveTo(0, 5);
ctx.lineTo(10, 5);
ctx.closePath();
ctx.stroke();
return patternCanvas;
};
我错在哪里?