检索当前的 javascript 文件名和行号

Coy*_*ote 5 javascript introspection ecmascript-5

是否有访问脚本当前文件名的标准方法?

C++PHP 中有类似__FILE__和的东西吗?__LINE__

如果没有这样做的标准方法,那么有哪些工具可以将此类功能添加到 .js 文件(预处理)?

我不是在寻找特定浏览器的解决方案(即ReferenceError: document is not defined

mač*_*ček 4

我不确定你在使用什么,但在 node.js 中你可以这样做

文件.js

var path = require("path");
console.log(path.basename(__filename));
// => file.js
Run Code Online (Sandbox Code Playgroud)

但在浏览器中无法做到这一点