SOURCE

function drawDiagonal() {
  var canvas = document.getElementById("diagonal");
  var context = canvas.getContext("2d");
  
  // 保存当前绘图状态
  context.save();
  
  //向右下方移动绘图上下文
  context.translate(70, 140);
  
  //以原点为起点,绘制与前面相同的线段
  context.beginPath();
  context.moveTo(0. 0);
  context.lineTo(70, -70);
  context.stroke();
  
  //恢复原有的绘图状态
  context.restore();
}

window.addEventListener("load", drawDiagonal, true);
console 命令行工具 X clear

                    
>
console