Quantcast
Channel: CNode:Node.js专业中文社区
Viewing all articles
Browse latest Browse all 14821

require 源码问题

$
0
0

基本已经搞懂了这个帖子说的意思了,但是还有一个地方想不太明白。

require()函数是在node/lib/internal/module.jsmakeRequireFunction()定义的,但是在源码最前面就有调用const errors = require('internal/errors');。 那自然是require()已经定义了,我在node/lib/internal/bootstrap_node.js找到了

    const { makeRequireFunction } = NativeModule.require('internal/module');
    // ...
    addCommandLineAPI('require', makeRequireFunction(consoleAPIModule));

但是const { makeRequireFunction } = NativeModule.require('internal/module');中在第一句const errors = require('internal/errors');会因为没有定义require()出错的呀。

把1年前的问题又翻出来问一遍,实在有些抱歉,但是希望能帮我解答一下,const { makeRequireFunction } = NativeModule.require('internal/module');到底是在那里定义的。


Viewing all articles
Browse latest Browse all 14821

Trending Articles