取代点差操作员?

时间:2018-08-07 03:35:13

标签: javascript

我具有以下功能。

alias.writeDialogue = function() {
    return writeDialogue(...arguments);
};

我希望支持IE,它不支持传播运算符。我应该用什么来代替...

1 个答案:

答案 0 :(得分:3)

使用private void OnDrawGizmos() { checkGizmoColor (); //for some reason, checkGizmoColor changes the color succesfully //but then the gizmo is not drawn //However, if i set Gizmos.color to red, the gizmo IS drawn Gizmos.color = Color.red; Gizmos.matrix = Matrix4x4.TRS(transform.position, transform.rotation, transform.localScale); if (useSphere) { Gizmos.DrawSphere (Vector3.zero, radius); } else { Gizmos.DrawCube(Vector3.zero, new Vector3(hitboxSize.x * 2, hitboxSize.y * 2, hitboxSize.z * 2)); // Because size is halfExtents } } private void checkGizmoColor() { switch (_state) { case ColliderState.Closed: Gizmos.color = inactiveColor; break; case ColliderState.Open: Gizmos.color = collisionOpenColor; break; case ColliderState.Colliding; Gizmos.color = collidingColor; break; default; break; } } 将参数数组转换为参数列表:

apply

但是最好将Babel集成到您的构建过程中,以便您可以使用现代语法编写并自动将其转换为与ES5兼容的语法。例如

https://babeljs.io/repl/

插入

return writeDialogue.apply(undefined, arguments);

你会得到

alias = {
  writeDialogue: function() {
    return writeDialogue(...arguments);
  }
}

Babel还将自动转换箭头功能"use strict"; alias = { writeDialogue: function (_writeDialogue) { function writeDialogue() { return _writeDialogue.apply(this, arguments); } writeDialogue.toString = function () { return _writeDialogue.toString(); }; return writeDialogue; }(function () { return writeDialogue.apply(undefined, arguments); }) }; constlet / async(带有RegeneratorRuntime),依此类推。这是必须的。