获得“未捕获的TypeError”

时间:2015-12-02 19:48:20

标签: javascript ecmascript-6 webpack babeljs

我正在使用Webpack& Babel转换一些ES6代码&我一直在uncaught type error。它还说:loadZipData @ bundle.js:98

Uncaught TypeError: _LoadDataClass2.default is not a function

以下是已编译的代码:

/******/ (function(modules) { // webpackBootstrap
/******/    // The module cache
/******/    var installedModules = {};

/******/    // The require function
/******/    function __webpack_require__(moduleId) {

/******/        // Check if module is in cache
/******/        if(installedModules[moduleId])
/******/            return installedModules[moduleId].exports;

/******/        // Create a new module (and put it into the cache)
/******/        var module = installedModules[moduleId] = {
/******/            exports: {},
/******/            id: moduleId,
/******/            loaded: false
/******/        };

/******/        // Execute the module function
/******/        modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);

/******/        // Flag the module as loaded
/******/        module.loaded = true;

/******/        // Return the exports of the module
/******/        return module.exports;
/******/    }


/******/    // expose the modules object (__webpack_modules__)
/******/    __webpack_require__.m = modules;

/******/    // expose the module cache
/******/    __webpack_require__.c = installedModules;

/******/    // __webpack_public_path__
/******/    __webpack_require__.p = "";

/******/    // Load entry module and return exports
/******/    return __webpack_require__(0);
/******/ })
/************************************************************************/
/******/ ([
/* 0 */
/***/ function(module, exports, __webpack_require__) {

    /*  
     *  CREATED: 11.25.2015
     */

    "use strict";

    var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();

    var _LoadDataClass = __webpack_require__(1);

    var _LoadDataClass2 = _interopRequireDefault(_LoadDataClass);

    function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

    function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

    var main = (function () {
        function main() {
            _classCallCheck(this, main);
        }

        _createClass(main, [{
            key: "fade",
            value: function fade(direction, fadeWhat) {
                //http://www.chrisbuttery.com/articles/fade-in-fade-out-with-javascript/
                var div = document.getElementById(fadeWhat);
                if (direction === "in") {
                    div.style.opacity = 0;
                    (function fade() {
                        var val = parseFloat(div.style.opacity);
                        if (!((val += .01) > 1)) {
                            div.style.opacity = val;
                            requestAnimationFrame(fade);
                        }
                    })();
                } else {
                    (function fade() {
                        div.style.opacity = 1;
                        if ((div.style.opacity -= .01) < 0) {
                            div.style.display = "none";
                        } else {
                            requestAnimationFrame(fade);
                        }
                    })();
                }
            }
        }, {
            key: "loadZipData",
                value: function loadZipData() {
  98                var zipData = new _LoadDataClass2.default();
                zipData.loadData("data/ZipCodeDatabase.csv", function (finalData) {
                    var zip = document.getElementById("studentZip").value;
                    for (var i = 0; i < finalData.length; i++) {
                        if (zip == finalData[i][0]) {
                            document.getElementById("studentCity").innerText = finalData[i][1];
                            document.getElementById("studentState").innerText = finalData[i][2];
                        }
                    }
                });
            }
        }]);

        return main;
    })();

    window.onload = function () {
        var mainObject = new main();
        mainObject.fade("in", "ppsLogo");
        document.getElementById("studentZip").addEventListener("change", mainObject.loadZipData);
    };

/***/ },
/* 1 */
/***/ function(module, exports) {

    /*  
     *  CREATED: 11.25.2015
     */

    "use strict";

    var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();

    function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

    var LoadDataClass = (function () {
        function LoadDataClass() {
            _classCallCheck(this, LoadDataClass);
        }

        _createClass(LoadDataClass, [{
            key: "loadData",
            value: function loadData(filePath, callback) {
                var request = new XMLHttpRequest();
                request.open("GET", filePath, true);
                request.send();
                request.onload = function () {
                    var COLUMNS = 3;
                    var data = undefined,
                        middleData = undefined,
                        finalData = [];
                    if (request.readyState === 4 && request.status === 200) {
                        data = request.responseText.split(/\n/);
                    }
                    for (var i = 0; i < data.length; i++) {
                        middleData = data[i].split(/,/);
                        finalData[i] = []; //makes it an MD array
                        for (var j = 0; j < COLUMNS; j++) {
                            finalData[i][j] = middleData[j];
                        }
                    }
                    callback(finalData);
                };
            }
        }]);

        return LoadDataClass;
    })();

/***/ }
/******/ ]);

错误发生在第98行。其余代码工作正常。

这是原始的主类文件:

"use strict";

import LoadDataClass from './LoadDataClass';

class main {
    constructor() {

    }

    fade(direction, fadeWhat) {
        //http://www.chrisbuttery.com/articles/fade-in-fade-out-with-javascript/
        let div = document.getElementById(fadeWhat);
        if (direction === "in") {
            div.style.opacity = 0;
            (function fade() {
                let val = parseFloat(div.style.opacity);
                if (!((val += .01) > 1)) {
                    div.style.opacity = val;
                    requestAnimationFrame(fade);
                }
            })();
        } else {
            (function fade() {
                div.style.opacity = 1;
                if ((div.style.opacity -= .01) < 0) {
                    div.style.display = "none";
                } else {
                    requestAnimationFrame(fade);
                }
            })();
        }
    }

    loadZipData() {
        let zipData = new LoadDataClass();
        zipData.loadData("data/ZipCodeDatabase.csv",  function(finalData) {
            let zip = document.getElementById("studentZip").value;
            for (let i = 0; i < finalData.length; i++) {
                if (zip == finalData[i][0]) {
                    document.getElementById("studentCity").innerText = finalData[i][1];
                    document.getElementById("studentState").innerText = finalData[i][2];
                    console.log(finalData[i][1]);
                    console.log(finalData[i][2]);
                }
            }
        });
    }
}

window.onload = function() {
    let mainObject = new main();
    mainObject.fade("in","ppsLogo");
    document.getElementById("studentZip").addEventListener("change", mainObject.loadZipData);
};

0 个答案:

没有答案