Threejs and orbitcontrol

有些话、适合烂在心里 提交于 2019-12-12 06:04:35

问题


I don't understand if it is a pure javascript mistake or not. In the class function below I added an eventListener that return me this error:

Uncaught TypeError: Cannot read property 'call' of undefined

I want to clarify that all the function called are correctly defined.

function OrbitController(v){
var that = this;
this.view = v;
this.controls = new THREE.OrbitControls(this.view.getCamera(),this.view.renderer.domElement);
this.controls.addEventListener( 'change', that.view.show());// Uncaught TypeError: Cannot read property 'call' of undefined
this.controls.target = new THREE.Vector3(0, 0, 0);
}

回答1:


Try with this solution:

this.controls.addEventListener( 'change',  function(){ that.view.show()});



回答2:


Unless that.view.show() returns a function, then it should just be

this.controls.addEventListener( 'change', that.view.show ); 


来源:https://stackoverflow.com/questions/29240089/threejs-and-orbitcontrol

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!