Есть примерно такой код
function tratata(){
this.draw = function(){
this.figure=function(){
....
}
}
}
После того, как я пишу
var a = new tratata()
a.draw().figure();
Выдает примерно такое => Cannot read property 'figure' of undefined
Что не так?
Вот конкретно код
function ttt(){
this.draw = function(){
this.triangle = function(x,y,a){
let h = Math.round(a*Math.sqrt(3)/2);
ctx.beginPath();
ctx.moveTo(x,y-Math.round(2*h/3));
ctx.lineTo(x+Math.round(a/2),y+h);
ctx.lineTo(x-a,y);
ctx.lineTo(x+Math.round(a/2),y-h);
this.stroke = function(color){
ctx.strokeStyle=color;
ctx.stroke();
};
};
};
};
Хотелось бы при написании примерно такого
var a = new ttt();
a.draw().triangle(100,100,100).stroke('white);
рисовался на канвасе треугольник с координатами 100 100 и стороной 100)