上QQ阅读APP看书,第一时间看更新
Importing and using external classes
An import can be accomplished with the keyword import, and can be declared in different ways, depending on what library you are using. An example of using Require.js is as follows:
- Go back to your text editor, create a file called import.ts, and add the following code:
import MyBand = require('./export');
console.log(Myband());
An example of using Common.js is as follows:
import { MyBand } from './export';
console.log(new Myband(['ZZ Top', 'Motorhead'], 3));
- The second method has been adopted by the Angular team, because Angular uses Webpack, a module bundler building modern web applications.