如何确定JavaScript中的当前行号? [英] How can I determine the current line number in JavaScript?

查看:170
本文介绍了如何确定JavaScript中的当前行号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

JavaScript是否有一种机制来确定当前正在执行的语句的行号(如果是,它是什么)?

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

推荐答案

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.

这篇关于如何确定JavaScript中的当前行号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆