2016-12-30 101 views
2

console.logdebugger语句添加到我的React.Components的正确方法是什么?React.Components中的console.log和调试器语句 - 意外令牌

只是删除它们产生Unexpected token错误:

export class ManageCoursePage extends React.Component { 
    debugger; 
    constructor(props, context) { 
    super(props, context); 

多一点帮助,但仍然会产生Unexpected 'debugger' statement

export class ManageCoursePage extends React.Component { 

    constructor(props, context) { 
    super(props, context); 
    debugger; 

甚至浏览器的console错误了Uncaught SyntaxError: Unexpected token ;

class Woot { 
    debugger; 
} 

这里到底发生了什么?

+1

我无法在第二个示例中重现错误: http://codepen.io/FullR/pen/JEPPxR – SimpleJ

+3

'class'主体只能包含方法声明。你不能在主体内部放置任意的语句。将'debugger'语句放在构造函数中应该可以工作。如果你得到*意外的调试器语句*,那么这可能是一个linter警告,当然你可以在调试时忽略它。你在用棉绒吗? –

+0

确认,在浏览器的控制台中测试时,在构造函数中设置'debugger'工作。 – nullsteph

回答

1

在构造函数或函数中移动调试器语句,它会正常工作。

+0

谢谢,经过一些试验和错误,它确实按预期工作。 – nullsteph