Table of Contents
1 全局对象
- global
console.log(global); // Object [global] { // global: [Circular], // clearInterval: [Function: clearInterval], // clearTimeout: [Function: clearTimeout], // setInterval: [Function: setInterval], // setTimeout: [Function: setTimeout] { [Symbol(util.promisify.custom)]: [Function] }, // queueMicrotask: [Function: queueMicrotask], // clearImmediate: [Function: clearImmediate], // setImmediate: [Function: setImmediate] { // [Symbol(util.promisify.custom)]: [Function] // } // }
- console
console.log(console) // { // log: [Function: bound consoleCall], // warn: [Function: bound consoleCall], // dir: [Function: bound consoleCall], // time: [Function: bound consoleCall], // timeEnd: [Function: bound consoleCall], // timeLog: [Function: bound consoleCall], // trace: [Function: bound consoleCall], // assert: [Function: bound consoleCall], // clear: [Function: bound consoleCall], // count: [Function: bound consoleCall], // countReset: [Function: bound consoleCall], // group: [Function: bound consoleCall], // groupEnd: [Function: bound consoleCall], // table: [Function: bound consoleCall], // debug: [Function: bound consoleCall], // info: [Function: bound consoleCall], // dirxml: [Function: bound consoleCall], // error: [Function: bound consoleCall], // groupCollapsed: [Function: bound consoleCall], // Console: [Function: Console], // profile: [Function: profile], // profileEnd: [Function: profileEnd], // timeStamp: [Function: timeStamp], // context: [Function: context], // [Symbol(kBindStreamsEager)]: [Function: bound ], // [Symbol(kBindStreamsLazy)]: [Function: bound ], // [Symbol(kBindProperties)]: [Function: bound ], // [Symbol(kWriteToConsole)]: [Function: bound ], // [Symbol(kGetInspectOptions)]: [Function: bound ], // [Symbol(kFormatForStdout)]: [Function: bound ], // [Symbol(kFormatForStderr)]: [Function: bound ] // }
- exports, require, module, _filename, _dirname(模块参数)
console.log(arguments.callee + ‘‘); // function (exports, require, module, __filename, __dirname) { // console.log(arguments.callee + ‘‘);
2 代码执行优先级
同步代码优先,例子如下
// 代码执行优先级 setTimeout(function () { setTimeout(function () { console.log(‘time out‘); }, 0); new Promise(resolve => { setTimeout(function () { console.log(‘start in Promise‘); }, 1); console.log(‘beg‘); resolve(); console.log(‘end‘); setTimeout(function () { console.log(‘end in Promise‘); }, 0); }).then(() => { console.log(‘finish‘); }); console.log(‘不要调皮‘); }, 100); // beg // end // 不要调皮 // finish // time out // start in Promise // end in Promise