SOURCE

console 命令行工具 X clear

                    
>
console
var can = document.getElementById('canvas');
var ctx = can.getContext('2d');

var draw = function(x1, y1, x2, y2, x3, y3, color, type) { 
    var ctx = this.ctx;
    ctx.beginPath();
    ctx.moveTo(x1, y1);
    ctx.lineTo(x2, y2);
    ctx.lineTo(x3, y3);
  	ctx[type + 'Style'] = color;
  	ctx.closePath();
    ctx[type]();
}

draw(50, 50, 175, 75, 50, 150, 'green', 'fill');
<canvas id="canvas" width="500" height="200"></canvas>