首页 > 在javascript中如何使用new?

在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
请问这是为什么呢??我该怎么写??



【热门文章】
【热门文章】