适用于回流和不可变的js ES6 webpack chrome

时间:2015-03-24 20:37:34

标签: javascript reactjs ecmascript-6 webpack refluxjs

我正在使用webpack和chrome

在ES6中遇到使用范围问题

这是我的代码:

'use strict'
import Reflux from 'reflux'
import Immutable from 'immutable'
import Something from 'something'
import Cursor from 'immutable/contrib/cursor'

// everything is working in this scope

export default Reflux.createStore({
    init: function() {
        console.log(Something) // Something Not defined
        console.log(Cursor) //Cursor Not defined
        console.log(Reflux) // Reflux Not defined
    },
    ... some other code
})

所以问题是,为什么在上面的范围内定义了东西,而不是在init函数的范围内?谢谢你的帮助

babel之后编译的代码就像     "使用严格的&#34 ;;

var _interopRequire = function (obj) { return obj && obj.__esModule ?     obj["default"] : obj; };

var Reflux = _interopRequire(require("reflux"));

var Immutable = _interopRequire(require("immutable"));

var Something = _interopRequire(require("something"));

var Cursor = _interopRequire(require("immutable/contrib/cursor"));

// everything is working in this scope

module.exports = Reflux.createStore({
    init: function init() {
        console.log(Something); // Something Not defined
        console.log(Cursor); //Cursor Not defined
        console.log(Reflux);
    } });

0 个答案:

没有答案