How can I determine the current line number in JavaScript?

前端 未结 8 1686
自闭症患者
自闭症患者 2020-11-27 13:46

Does JavaScript have a mechanism for determining the line number of the currently executing statement (and if so, what is it)?

8条回答
  •  借酒劲吻你
    2020-11-27 14:08

    Inject the following snippet to your code:

    console.debug("line:", /\(file:[\w\d/.-]+:([\d]+)/.exec(new Error().stack)[1]);
    

提交回复
热议问题