Table of Contents
1. 全局对象
2. 代码执行优先级
- 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
Created: 2019-06-23 周日 23:42
- http://validator.w3.org/check?uri=referer
- #+LATEX_HEADER: \usepackage{
- ctex
- }
* 全局对象
- - global
- :g:
- #+BEGIN_SRC JavaScript
- 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]
- // }
- // }
- #+END_SRC
- :END:
- - console
- :g:
- #+BEGIN_SRC JavaScript
- 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 ]
- // }
- #+END_SRC
- :END:
- - exports, require, module, __filename, __dirname(模块参数)
- :g:
- #+BEGIN_SRC JavaScript
- console.log(arguments.callee + '');
- // function (exports, require, module, __filename, __dirname) {
- // console.log(arguments.callee + '');
- #+END_SRC
- :END:
* 代码执行优先级
同步代码优先, 例子如下
- :g:
- #+BEGIN_SRC JavaScript
- // 代码执行优先级
- 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
- #+END_SRC
- :END:
- node
来源: http://www.bubuko.com/infodetail-3102078.html