SystemJS导入“;基本脚本“;来自目录,类似于Python
SystemJS import "base script" from directory, like in Python
是否可以使用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
bootstrap.js
导入目录以导入基本脚本(__init__.js
或module1.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
是的,这是可能的。使用index.js
文件:
模块1/index.js
然后您可以import "./module1";
JavaScript本身不是一种基于模块的语言(还不是)。为了做到这一点,您需要包括另一个库,如RequireJS
相关文章:
- Javascript日期格式类似于ISO,但本地
- toBoolean方法类似于toString
- 州和城市选择框类似于国家细分页面
- 通过传递图像的URL通过javascript读取/处理图像-类似于PHP中的file_get_contents
- 在BootStrap菜单栏中为所选项目设置背景,类似于BootStrap中的父导航选项
- 检测演示者工具的事件,类似于onmousedown
- 类似于Prism的Knockout js框架
- 创建类似于Google analytics的分析地图
- 敲除js变量设置类似于调用函数
- 如何处理javascript中的循环引用,类似于Excel提供迭代限制的方式
- 用null填充稀疏数组(类似于压缩两个数组)
- jQuery模态弹出的行为类似于确认和警报对话框
- SystemJS导入“;基本脚本“;来自目录,类似于Python
- 有没有类似于Python pass语句的JavaScript,它什么都不做
- JavaScript函数,类似于Python的range()
- 我怎么能调试在nodejs,任何类似于pdb或撬在Ruby或Python的工具
- 有没有类似于Python'JavaScript或jQuery中的所有函数是什么
- 有什么类似于Python's在Javascript中的numpy.apply_along_axis
- 如何在JavaScript中对函数进行类似于Python timeit的计时
- sprintf()用于JavaScript,其行为类似于python的's format(%)