gpt4 book ai didi

node.js - __file 和 __dirname 是在编译时还是在运行时求值?

转载 作者:搜寻专家 更新时间:2023-10-31 23:05:44 26 4
gpt4 key购买 nike

在 node.js 中有全局变量 __filename__dirname - 它们是在加载时由编译器扩展的,类似于它在 c++ 预处理器中的完成方式替换 __FILE__(和其他魔术常量)或者这些是在运行时评估的吗?

我在任何地方都找不到此信息。

最佳答案

它在执行每个文件之前被声明为一个变量。

对于入门级的文件,这样做了deep in the source code .

对于普通模块,完成了here ,称为 here .

关于node.js - __file 和 __dirname 是在编译时还是在运行时求值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19519477/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com