我是 typescript 新手,需要 js。我见过几种在 typescript 中导入模块的方法。但我不清楚下面的代码在做什么..
1./// <reference path="foo.ts" />
2.import {utils} from "./util";
3.require(["bar"],function(bar){
//use module here
});
4.define(["bar"],function(bar){
//use module here
});
5.requirejs(["bar"],function(bar){
//use module here
});
它们之间有何不同。请任何人帮忙。
最佳答案
- TypeScript-specific way of loading modules .
- Is the standard way of loading modules .
- 和
- 和
- 怎么样 RequireJS加载模块。
RequireJS 是一个在 JS 有加载模块的官方语法之前就存在的库。 RequireJS 模块是使用 define
调用来定义的,传入依赖项和一个在加载所有依赖项时运行的函数。 require
调用会启动加载过程,通常出现在应用程序的一开始。
import
/export
是加载 JavaScript 模块的标准语法。 iirc 去年对语法进行了标准化。模块解析尚未标准化,目前也未由任何浏览器实现。但这种语法被不同的工具用来“编译”JS。
我无法解释太多 TypeScript 的内容。这篇文章应该为您提供所需的一切。
The /// directive is the most common of this group. It serves as a declaration of dependency between files.
关于javascript - typescript中导入模块的方式有哪些以及require js在模块加载中的作用是什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36937962/