且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

通过`bind`将函数参数传递给另一个函数

更新时间:2023-11-09 23:13:40

愿您可以使用 arguments 这样的对象 ??

May you can use the arguments object like this ??

_bezier.processBezier = function (mX1, mY1, mX2, mY2) {
  return _bezier.render.bind(this, arguments); // <--- bind all the arguments and the context "this"
};

_bezier.render = function(){ // <--- aX is not required anymore instead use arguments object
  var args = arguments[0]; // <--- this corresponds to [mX1, mY1, mX2, mY2]
  var aX = arguments[1]; // <--- this corresponds to aX now
  if (args[0] === args[1] && args[2] === args[3]) return aX; // <--- notice args object here

  if (aX === 0) return 0;
  if (aX === 1) return 1; 
  return _bezier.computeBezier(_bezier.gx(aX), mY1, mY2);     
};