SOURCE

console 命令行工具 X clear

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

		var points = [],
			moveX,
			moveY,
			toX,
			toY

		canvas.addEventListener('mousedown', function (e) {
			moveX = e.offsetX
			moveY = e.offsetY
			canvas.addEventListener('mousemove', drawLine)
		})
		canvas.addEventListener('mouseup', function (e) {
			points.push({
			  mx: moveX,
			  my: moveY,
			  x: toX,
			  y: toY
			});
			canvas.removeEventListener('mousemove', drawLine)
		})
		function drawLine(e) {
			toX = e.offsetX
			toY = e.offsetY
			ctx.clearRect(0,0, 600, 600);
			points.forEach(function(point, i) {
				ctx.beginPath();
				ctx.moveTo(point.mx, point.my);
				ctx.lineTo(point.x, point.y);
				ctx.closePath();
				ctx.stroke();
			});
			ctx.beginPath();
			ctx.moveTo(moveX, moveY);
			ctx.lineTo(toX, toY);
			ctx.closePath();
			ctx.stroke();
		}
<canvas id="canvas" width="400" height="400">
</canvas>
#canvas {
  display: block;
  margin: 50px auto;
  border: #666 1px solid;
  cursor: crosshair;
}