3

是否可以使用SystemJS从类似模块的目录中导入“基本脚本” ,例如 Python 的__init__.py

例子:

目录结构

app/
  module1/
    __init__.js       // or module1.js
    module1.weeble.js
    module1.thingy.js
  module2/
    __init__.js       // or module2.js
    module2.weeble.js
    module2.thingy.js
  bootstrap.js

模块1/__init__.js

import Weeble from "./module1.weeble"
import Thingy from "./module1.thingy"

class Module1 {
  constructor() {
    this.weeble = new Weeble();
    this.thingy = new Thingy();
  }
}

export default Module1

引导程序.js

导入目录以导入基本脚本(__init__.jsmodule1.js)或其他东西:

import Module1 from "./module1"
import Module2 from "./module2"

let module1 = new Module1();
let module2 = new Module2();

// INSTEAD OF
// import Module1 from "./module1/__init__"
// OR
// import Module1 from "./module1/module1"

这可能吗?__init__.py如果该目录中存在,Python 将目录作为模块导入

# so one doesn't have to type
from module/__init__.py import module_part

# but only
from module import module_part

# or to import the entire module 
import module
4

2 回答 2

0

是的,这是可能的。为此使用index.js文件:

模块1/index.js

那么你也能import "./module1";

于 2015-10-09T14:39:13.067 回答
-1

JavaScript 本身不是基于模块的语言语言(还不是)。为此,您需要包含另一个库,例如RequireJS

于 2015-02-23T10:51:14.110 回答