typescript module

Module: module enables developers to reuse code is divided into units. Developers can decide what resources he would modules (classes, methods, variables) for external use exposed to, what resources are used only within the module

 

Ts in which a file is a module, and no special identification. Inside the module to support two key characteristics of the module, two characteristics that export and import

 

a.ts
// External exposure of the prop1 variables, and do not expose the external variable prop2 
Export var the prop1: the any;
 var prop2; 

// Method func1 exposed outside, and not exposed outside func2 
Export function func1 () {}
 function func2 () {} 

// External exposure class1, and not exposed outside Class2 
Export the Class1 class {} 
class Class2 {}

 

b.ts
import { prop1, func1, Class1 } from "./a";
console.log(prop1)
func1();
new Class1();

This is ts module, which is written in the file export, to decide what the external exposure, b.ts which did not call a.ts of external resources directly exposed

 

Guess you like

Origin www.cnblogs.com/wzndkj/p/11665514.html