JS file call each other

When we write js code, call each other often encounter between two js files directly on the code:
messageText.js

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
// definition array 
var msgArray = [
{name: 'the In function', value: 'the function'},
{name: 'Not declared in the this scope WAS', value: "is not declared in this scope"},
];

// define the constant
var messageText = {

a_name: 'John Doe',

b_name: 'John Doe',

}
exports.msgArray = msgArray;
exports.messageText = messageText;

In A.js the call messageText.js

1
2
3
4
5
6
const msg_1 = require("./messageText");
for(var i=0; i < msg_1.msgArray.length; i++)
{
var message = data1.replace(msg_1.msgArray[i].name, msg_1.msgArray[i].value);
data1 = message;
}

In the above example, I made a string of data1 this localization process, is to replace the array name as a value;
if you want constant B.js references, it is very simple:

1
msg_1.messageText.a_name

Such value can be obtained in the a_name B.js.

ts file usage calls between some differences, as follows:
messageText.ts

1
2
3
export class MessageText {
public static name: string = '张三';
}

Js call messageText.ts call in the A.ts

1
2
import {MessageText} from 'vs / workbench / api / common / messageText'; // Note form '' your project directory 
console.log (MessageText.name);

Original: Large column  JS file call each other


Guess you like

Origin www.cnblogs.com/chinatrump/p/11614944.html