Node. when a global Object in js is global, all global variables are the attributes of the global object. in js, we can directly access the global attribute without including it in the application. Learning points:
-_ Filename
-_ Dirname
-SetTimeout (cb, MS)
-SetInterval (cb, MS)
-ClearTimeout (t)
-Console
-Process
Node. js Global Object
Node. when a global Object in js is global, all global variables are the attributes of the global object. in js, we can directly access the global attribute without including it in the application.
Global Object and global variable
Global serves as the host of global variables.
When we define a global variable, this variable will also become the global attribute of the global object.
_ Filename indicates the file name of the script being executed.
[Code] console. log ("file path:" + _ filename );
_ Dirname indicates the directory where the script is currently executed
[Code] console. log ("directory of the file:" + _ dirname );
SetTimeout (cb, MS) Extension object
SetInterval (cb, MS) timer object
ClearTimeout (t) Clear the extension
Case: main. js
[Code] console. log ("file path:" + _ filename); console. log ("directory of the file:" + _ dirname); var printHello = function () {console. log ("Hello, World");} // call the function var t = setTimeout (printHello, 1000) after 1 s; // clear the extended clearTimeout (t );
Case: console. js
[Code] console.info ("program execution started:"); var counter = 10; console. log ("count: % d", counter); console. time ("Get Data"); console. timeEnd ("Get Data"); console.info ("program execution completed"); // process is triggered when the process is about to exit. on ('exit ', function (code) {// the following code will never execute setTimeout (function () {console. log ("this code will not be executed") ;}, 0); console. log ("Exit code:", code) ;}); console. log ("program execution ended ");
Case 3: process. js
[Code] // output to Terminal process. stdout. write ("Hello World! "+" \ N "); // read through the parameter // an array is returned by the argv attribute, which is composed of parameters when the script is executed by the command line. // Its first member is always node, the second member is the script file name, and the other members are the parameters of the script file. Process. argv. forEach (function (val, index, array) {console. log (index + ":" + val); // 0: D: \ nodeJS installation package \ node.exe // 1: E: \ node \ global object \ process. js}); // obtain and execute the supervisor // D: \ nodeJS installation package \ node.execonsole.log(process.exe cPath); // platform information // wind32console. log (process. platform); // output the current directory console. log ("Current Directory:" + process. cwd (); // outputs the current console version. log ('current version: '+ process. version); // output memory usage console. log (process. memoryUsage ());
The above is the content of the Node. js Global Object. For more information, see PHP Chinese Network (www.php1.cn )!