我想做类似的事情:
function example(name){
var age = 0;
var started = false;
var start = function(){
started = true;
}
this.forward = function(){
age++;
}
console.log( SOMECODE );
}
example('boby');
我希望在SOMECODE
中打印一些类似于:
name: "boby"
age: 0
started: false
start: [Function]
forward: [Function]
我喜欢这样写:
function inspect(locals){
for(var name in locals){
console.log(name, ':', locals[name]);
}
}
console.log(inspect(example.locals));
// or
console.log(inspect(example.stack[-1].locals));
// or
console.log(inspect(example.clousure));
我的目标是编写自动化工具,用于在我的程序中进行调试,或编写一般的prupouse日志。或者使用局部变量值打印调用堆栈。