【发布时间】:2013-08-06 11:39:26
【问题描述】:
我正在使用http://nodejs.org/api/debugger.html
我在方法中放了一个断点:
Processor.prototype.myMethod = function() {
console.log(this.constructor.name); // returns Processor
debugger;
this.otherMethod(123);
}
然后我调用node debug myapp.js 并到达断点。但是当我输入this.constructor.name 时,我得到的是“对象”,而不是“处理器”。
我可以访问该范围内的this 还是必须使用https://github.com/node-inspector/node-inspector 之类的东西?
编辑:我似乎无法从调试器访问任何脚本变量,甚至无法访问 Processor。我在 OS X 上使用 v0.10.13。
【问题讨论】:
-
解决方法可能是
var self = this,然后在调试器中访问self。 -
@ThiefMaster 这似乎不起作用:
ReferenceError: self is not defined -
行不通。这样做只有在深入到同一个函数作用域时才有用,这似乎不是因为他使用
prototype来创建类。 -
我的意思是把它放在你的代码中
debugger语句之前。 -
@ThiefMaster 是的,这就是我所做的,这就是我得到的错误。
标签: node.js