How can I determine the current line number in JavaScript?

前端 未结 8 1683
自闭症患者
自闭症患者 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:12

    var thisline = new Error().lineNumber

    If that doesn't work in whatever environment you're using, you can try:

    var stack = new Error().stack

    Then hunt through the stack for the line number.

提交回复
热议问题