Work with the JS object. Something is wrong with this?

There is code like this
tratata function(){
this.draw = function(){
this.figure=function(){
....
}
}
}

After I write
var a = new tratata()
a.draw().figure();

This gives about => Cannot read property 'figure' of undefined
What's wrong?

That's exactly the code
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();
};

};
};
};

I would like when writing about this
var a = new ttt();
a.draw().triangle(100,100,100).stroke('white);

painted on the canvas a triangle with coordinates 100 100 party 100)
June 27th 19 at 15:29
2 answers
June 27th 19 at 15:31
a.draw().figure()is the same as
var drawResult = a.draw();
drawResult.figure();

hint: draw returns nothing
Or something doing wrong, or not working) the same error - catherine33 commented on June 27th 19 at 15:34
Of course the same error, I wrote to you, that you understand why the error. - willow.Hand commented on June 27th 19 at 15:37
June 27th 19 at 15:33
You have so
tratata function(){
 this.draw = function(){
this.figure=function(){}
}
}

and it is necessary apparently
tratata function(){
 this.draw = function(){}
this.figure=function(){}
}
No, it just still attached to do) - catherine33 commented on June 27th 19 at 15:36
: heh, read about scope in this case
tratata function(){
 var that = this;
 this.draw = function(){
that.figure=function(){}
}
}
- willow.Hand commented on June 27th 19 at 15:39

Find more questions by tags JavaScript