【发布时间】:2017-02-27 17:05:47
【问题描述】:
这样的函数定义有什么好处:obj = { func: function(){return function func(){return this.something;};}() }
故事: 我正在寻找一种如何将 Three.js Vector3 围绕轴旋转一定角度的方法,并发现了这一点: How to rotate a Three.js Vector3 around an axis? 我对该函数的工作原理很感兴趣并进行了查找:https://github.com/mrdoob/three.js/blob/master/src/math/Vector3.js。函数如下所示:
applyAxisAngle: function () {
var quaternion;
return function applyAxisAngle( axis, angle ) {
if ( quaternion === undefined ) quaternion = new Quaternion();
return this.applyQuaternion( quaternion.setFromAxisAngle( axis, angle ) );
};
}(),
那么这种定义函数的方式的原因是什么?
【问题讨论】:
-
考虑到
d和n的位置,anvantage有些错别字 -
优点是隐藏
quaternion。applyAxisAngle可以用,别人不行。
标签: javascript function three.js