+
 新版

在javascript中如何使用new

连七 发布于 2016/08/15 22:53
阅读 445
收藏 0
请问我像这样写
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;
            };

最后我初始化的时候

var detectCollision = new DetectCollision();
            //console.log(detectCollision);
            collisionArray = new DetectCollision().addDetector(cases1);

却提示我

DetectCollision is not a constructor

请问我该怎么写呢??







加载中
0
我是偶哦
我是偶哦
运行你的代码没有出现上述问题,不过你是不是把初始化代码放到声明代码前面了。
OSCHINA
登录后可查看更多优质内容
返回顶部
顶部