简体   繁体   中英

Threejs and orbitcontrol

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);
}

除非that.view.show() 返回一个函数,否则它应该是

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

尝试以下解决方案:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM