我想用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)
我怎样才能找回它们?
在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)
使用此功能的好处是什么(如果有的话)而不是 …