我試圖將我的threejs項目分解成更小的模塊,並且我遇到了困難時期。以此功能爲例:將threejs的IIFE函數轉換爲es6?
var updateCamera = (function() {
var euler = new THREE.Euler(0, 0, 0, 'YXZ');
return function() {
euler.x = motion.rotation.x;
euler.y = motion.rotation.y;
camera.quaternion.setFromEuler(euler);
camera.position.copy(motion.position);
camera.position.y += 10.0;
};
})();
假設我想將此updateCamera函數分解爲它自己的文件並導入它。由於自我執行,我有點困惑。任何人都可以幫我一把嗎?
我將引用這個問題找到答案:http://stackoverflow.com/問題/ 32746615 /命名空間與 - iife功能於ES6。 ES6 IIFE可以用幾種方式編寫,但我更喜歡用塊範圍包裝{...}替換它。 – autoboxer
你在哪裏得到變量'camera'和'motion'? –