小编som*_*ent的帖子

获取画布上下文的最后一个点的坐标

我想用CanvasRenderingContext2D.prototype创建一个arrowTo函数.要做到这一点,我需要得到最后一点的坐标.例如

//... 
var ctx = someCanvas.getContext('2d');

ctx.moveTo(10,40);
//the coordinates of the last point are now (10,40)

ctx.lineTo(50,50);
//and now it's (50,50)

//...
Run Code Online (Sandbox Code Playgroud)

我怎样才能找回它们?

javascript html5 canvas html5-canvas

14
推荐指数
2
解决办法
6018
查看次数

为什么MDC原型函数以这种方式编写?

在MDC中,有大量代码片段意味着在不支持它们的浏览器中实现对新ECMAScript标准的支持,例如Array.prototype.map函数:

if (!Array.prototype.map)
{
  Array.prototype.map = function(fun /*, thisp */)
  {
    "use strict";

    if (this === void 0 || this === null)
      throw new TypeError();

    var t = Object(this);
    var len = t.length >>> 0;
    if (typeof fun !== "function")
      throw new TypeError();

    var res = new Array(len);
    var thisp = arguments[1];
    for (var i = 0; i < len; i++)
    {
      if (i in t)
        res[i] = fun.call(thisp, t[i], i, t);
    }

    return res;
  };
}
Run Code Online (Sandbox Code Playgroud)

使用此功能的好处是什么(如果有的话)而不是 …

javascript

12
推荐指数
1
解决办法
804
查看次数

标签 统计

javascript ×2

canvas ×1

html5 ×1

html5-canvas ×1