Object.defineProperty(global, '__stack', {
get: function(){
var path = require('path');
var stackReg = /at\s+(.*)\s+\((.*):(\d*):(\d*)\)/i;
var stackReg2 = /at\s+()(.*):(\d*):(\d*)/i;
var stacklist = (new Error()).stack.split('\n').slice(3);
var s = stacklist[0];
var sp = stackReg.exec(s) || stackReg2.exec(s);
var data = {};
if (sp && sp.length === 5) {
data.method = sp[1];
data.path = sp[2];
data.line = sp[3];
data.pos = sp[4];
data.file = path.basename(data.path);
}
return data;
}
});
//行号
Object.defineProperty(global, '__line', {
get: function(){
return __stack['line'];
}
});
//文件名
Object.defineProperty(global, '__file', {
get: function(){
return __stack['file'];
}
});
//方法名
Object.defineProperty(global, '__func', {
get: function(){
return __stack['method'];
}
});