Object.defineProperty(global, '__stack', { get: function(){ var orig = Error.prepareStackTrace; Error.prepareStackTrace = function(_, stack){ return stack; }; var err = new Error; Error.captureStackTrace(err, arguments.callee); var stack = err.stack; Error.prepareStackTrace = orig; return stack; }});Object.defineProperty(global, '__line', { get: function(){ return __stack[1].getLineNumber(); }});console.log(__line);以上将记录
19。
结合使用,
arguments.callee.caller您可以更接近通过宏在C中获得的有用日志的类型。



