webgl - 在javascript中如何使用new?
本文介绍了webgl - 在javascript中如何使用new?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
问 题
请问我像这样写`
var DetectCollision = function () {
//被检测的物体
this.detectArray = [];
this.movingCube = function(){
var geometry = new THREE.SphereGeometry(0.5);
var cube = new THREE.Mesh(geometry);
cube.visible = false;
return cube;
};
};
DetectCollision.prototype.removeDetector = function(object){
var index = this.detectArray.indexOf(object);
if(index === -1) return;
this.detectArray.splice(index, 1);
};
//在数组中添加元素
DetectCollision.prototype.addDetector = function(object){
if(this.detectArray.indexOf(object) !== -1) return;
this.detectArray.push(object);
return this;
};`
当我使用new操作符时
var detectCollision = new DetectCollision();
collisionArray = new DetectCollision().addDetector(cases1);
却提示DetectCollision is not a constructor
请问这是为什么呢??我该怎么写??
解决方案
这篇关于webgl - 在javascript中如何使用new?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文