console.log(global);
/*
Object [global] {
global: [Circular],
clearInterval: [Function: clearInterval],
clearTimeout: [Function: clearTimeout],
setInterval: [Function: setInterval],
setTimeout: [Function: setTimeout] {
[Symbol(nodejs.util.promisify.custom)]: [Function]
},
queueMicrotask: [Function: queueMicrotask],
clearImmediate: [Function: clearImmediate],
setImmediate: [Function: setImmediate] {
[Symbol(nodejs.util.promisify.custom)]: [Function]
}
}
*/
var v1 = "This is a global variable";
var func1 = function () { console.log("This is a global function"); };
console.log(v1); // This is a global variable
console.log(func1) // [Function: func1]
// setTimeout
var func2 = function (req) { console.log(req); };
// 在定义的时候就开始执行了
var timer = setTimeout(func2,3000,"This is a params,it can be many");
clearTimeout(timer) // 立刻清除,则不执行
// setInterval 循环执行
// 在定义的时候,就开始执行了,调用只是为了清除
var set1 = setInterval(function () {
console.log("hello");
},1000);
setTimeout(() => {
clearInterval(set1);
}, 5000);
// 模块调用
var foo = require("./foo");