2017-07-08 20 views
0

奇怪的情況是browserify調用我的功能?

我有一個名爲THREE.Vector3.prototype.changeBasis不是由我調用的函數,但是仍然會返回一個類型的錯誤......顯然,它是由Browserify叫!

堆棧跟蹤直接指向第1行,第246列。此行由Browserify生成。

這是1號線怎麼看在我的包文件:

(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){ 

,這是它的外觀由246列,並起:

t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){ 

的問題是:爲什麼是1號線電話我的功能..?它不應該。

這是堆棧跟蹤的樣子全:函數的定義裏面

TypeError: transformMatrix is undefined[Learn More] tb.js:16065:27 
    changeBasis file:///C:/Users/Jon/Auchitect/frontend/js/tb.js:16065:27 
    [90]< file:///C:/Users/Jon/Auchitect/frontend/js/tb.js:16063:48 
    s file:///C:/Users/Jon/Auchitect/frontend/js/tb.js:1:246 
    s/< file:///C:/Users/Jon/Auchitect/frontend/js/tb.js:1:305 
    [86]< file:///C:/Users/Jon/Auchitect/frontend/js/tb.js:15220:1 
    s file:///C:/Users/Jon/Auchitect/frontend/js/tb.js:1:246 
    s/< file:///C:/Users/Jon/Auchitect/frontend/js/tb.js:1:305 
    [85]< file:///C:/Users/Jon/Auchitect/frontend/js/tb.js:14689:20 
    s file:///C:/Users/Jon/Auchitect/frontend/js/tb.js:1:246 
    s/< file:///C:/Users/Jon/Auchitect/frontend/js/tb.js:1:305 
    [5]< file:///C:/Users/Jon/Auchitect/frontend/js/tb.js:878:17 
    s file:///C:/Users/Jon/Auchitect/frontend/js/tb.js:1:246 
    s/< file:///C:/Users/Jon/Auchitect/frontend/js/tb.js:1:305 
    [17]< file:///C:/Users/Jon/Auchitect/frontend/js/tb.js:4528:15 
    s file:///C:/Users/Jon/Auchitect/frontend/js/tb.js:1:246 
    s/< file:///C:/Users/Jon/Auchitect/frontend/js/tb.js:1:305 
    [61]< file:///C:/Users/Jon/Auchitect/frontend/js/tb.js:11972:24 
    s file:///C:/Users/Jon/Auchitect/frontend/js/tb.js:1:246 
    s/< file:///C:/Users/Jon/Auchitect/frontend/js/tb.js:1:305 
    [40]< file:///C:/Users/Jon/Auchitect/frontend/js/tb.js:5947:33 
    s file:///C:/Users/Jon/Auchitect/frontend/js/tb.js:1:246 
    s/< file:///C:/Users/Jon/Auchitect/frontend/js/tb.js:1:305 
    [35]< file:///C:/Users/Jon/Auchitect/frontend/js/tb.js:5109:20 
    s file:///C:/Users/Jon/Auchitect/frontend/js/tb.js:1:246 
    e file:///C:/Users/Jon/Auchitect/frontend/js/tb.js:1:425 
    <anonymous> file:///C:/Users/Jon/Auchitect/frontend/js/tb.js:1:11 

兩個第一線點,然後堆棧跟蹤跳躍直奔行我束文件1(命名爲tb.js)。

這是我如何定義我的功能:

THREE.Vector3.prototype.changeBasis = function changeBasis(transformMatrix, lb0, lb1, lb2, local_to_global) { // line 163063 in the bundle 

     if (!local_to_global) { transformMatrix.getInverse(transformMatrix) } // line 163065 in the bundle 

     return this.applyMatrix3(transformMatrix); 

}(); 

這是在我的函數定義的文件:

"use strict"; 

var THREE = require('three'); 


var loadTexture_promise = (texture_path, texture_loader) => { 
    var texture_promise; 

    if (  loadTexture_promise.texturePromises_cache[texture_path] !== undefined) { 
     return loadTexture_promise.texturePromises_cache[texture_path] 
    } 

    texture_promise = new Promise(
     function(resolve, reject) 
     { 
      texture_loader.load(
       texture_path, 
       function (texture) { 
        // Success callback of TextureLoader 
        // We're done, so tell the promise it is complete 
        resolve(texture); 
       }, 
       function (XmlHttpRequest_instance) { 
        // Progress callback of TextureLoader 
       }, 
       function (unknown_parameter) { 
        // Failure callback of TextureLoader 
        // Reject the promise with the failure 
        reject(new Error('Could not load texture ' + texture_path)); 
       } 
      ); 
     } 
    ); 

    // add texture_promise to cache: 
    loadTexture_promise.texturePromises_cache[texture_path] = texture_promise; 

    return texture_promise; 
}; 
// establish cache object on the loadTexture_promise function: 
loadTexture_promise.texturePromises_cache = []; 



THREE.PointHelper = function (position = {x:0,y:0,z:0}, size = 20) { 

    var geometry = new THREE.Geometry(); 
    var material = new THREE.LineBasicMaterial({ vertexColors: THREE.VertexColors }); 

    this.colorX_origo = new THREE.Color(1, 0, 0); 
    this.colorX_end = new THREE.Color(1, 0.6, 0); 
    this.colorY_origo = new THREE.Color(0, 1, 0); 
    this.colorY_end = new THREE.Color(0.6, 1, 0); 
    this.colorZ_origo = new THREE.Color(0, 0, 1); 
    this.colorZ_end = new THREE.Color(0, 0.6, 1); 

    geometry.vertices.push(
     new THREE.Vector3(-size, 0, 0), new THREE.Vector3(0, 0, 0), 
     new THREE.Vector3( size, 0, 0), new THREE.Vector3(0, 0, 0), 
     new THREE.Vector3(0, -size, 0), new THREE.Vector3(0, 0, 0), 
     new THREE.Vector3(0, size, 0), new THREE.Vector3(0, 0, 0), 
     new THREE.Vector3(0, 0, -size), new THREE.Vector3(0, 0, 0), 
     new THREE.Vector3(0, 0, size), new THREE.Vector3(0, 0, 0) 
    ); 

    geometry.colors.push(
     this.colorX_end, this.colorX_origo, this.colorX_end, this.colorX_origo, 
     this.colorY_end, this.colorY_origo, this.colorY_end, this.colorY_origo, 
     this.colorZ_end, this.colorZ_origo, this.colorZ_end, this.colorZ_origo); 

    THREE.Line.call(this, geometry, material); 

    this.position.set(position.x, position.y, position.z); 

}; 

THREE.PointHelper.prototype = Object.create(THREE.LineSegments.prototype); 
THREE.PointHelper.prototype.constructor = THREE.PointHelper; 


var origo = new THREE.Vector3(); 
THREE.VectorHelper = function (end, color) { 

    var geometry = new THREE.Geometry(); 
    var material = new THREE.LineBasicMaterial({ vertexColors: THREE.VertexColors }); 

    geometry.vertices.push(origo, end); 

    if (typeof color !== "undefined") { this.color = new THREE.Color(color ); } 
    else        { this.color = new THREE.Color(0xffffff); } 
    geometry.colors.push(this.color, this.color); 

    THREE.Line.call(this, geometry, material); 
}; 


THREE.VectorHelper.prototype = Object.create(THREE.Line.prototype); 
THREE.VectorHelper.prototype.constructor = THREE.VectorHelper; 

THREE.VectorHelper.prototype.setColor = function(color) { 
    this.color.set(color); 
    this.geometry.colorsNeedUpdate = true; 
    return this 
}; 


THREE.LineHelper = function (start, end, color) { 

    var geometry = new THREE.Geometry(); 
    var material = new THREE.LineBasicMaterial({ vertexColors: THREE.VertexColors }); 

    geometry.vertices.push(start, end); 

    if (typeof color !== "undefined") { this.color = new THREE.Color(color ); } 
    else        { this.color = new THREE.Color(0xffffff); } 
    geometry.colors.push(this.color, this.color); 

    THREE.Line.call(this, geometry, material); 

}; 

THREE.LineHelper.prototype = Object.create(THREE.Line.prototype); 
THREE.LineHelper.prototype.constructor = THREE.LineHelper; 

THREE.LineHelper.prototype.setColor = function(color) { 
    this.color.set(color); 
    this.geometry.colorsNeedUpdate = true; 
    return this 
}; 

// fixme: consider having it take a THREE.Plane as argument: 
THREE.PlaneHelper = function (planeNormal, planeCenter, size, step, colorCenterLine, colorGrid, debug) { 

    if (typeof colorGrid === "undefined") { colorGrid = colorCenterLine; } 

    THREE.GridHelper.call(this, size, step, colorCenterLine, colorGrid); 

    if (debug) { console.log("this.rotation before quaternion: ", this.rotation.clone()); } 

    this.position.set(planeCenter.x, planeCenter.y, planeCenter.z); 

    var standardPlaneNormal = new THREE.Vector3(0, 1, 0); 
    var quaternion = new THREE.Quaternion().setFromUnitVectors(standardPlaneNormal, planeNormal); 
    this.rotation.setFromQuaternion(quaternion); 

    if (debug) { 
     console.log("quaternion after setFromUnitVectors: ", quaternion.clone()); 
     console.log("this.rotation after quaternion: ", this.rotation.clone()); } 
}; 

THREE.PlaneHelper.prototype = Object.create(THREE.GridHelper.prototype); 
THREE.PlaneHelper.prototype.constructor = THREE.PlaneHelper; 



THREE.Vector3.prototype.rejectOnVector = function() { 

    var v1; 

    return function rejectOnVector(planeNormal) { 

     if (v1 === undefined) v1 = new THREE.Vector3(); 

     v1.copy(this).projectOnVector(planeNormal); 

     return this.sub(v1); 

    }; 

}(); 


THREE.Vector3.prototype.changeBasis = function changeBasis(transformMatrix, lb0, lb1, lb2, local_to_global) { // lb = local basis 

     if (!local_to_global) { transformMatrix.getInverse(transformMatrix) } 

     return this.applyMatrix3(transformMatrix); 

}(); 


module.exports = { 
    loadTexture_promise 
}; 
+1

'...}()'是一個函數調用。 – melpomene

回答

0

我還沒有看到我的函數被執行後自己的權利定義。