Is there any way to get the source line number in Javascript, like __LINE__
for C or PHP?
The . repeat() method returns a new string, which is the original string repeated the specified number of times.
The semi-colon, ; , in JavaScript represents an “end of statement” or “statement delimiter”. It tells JavaScript not to parse any more code, and to go ahead and execute the statement up to that point.
“This” keyword refers to an object that is executing the current piece of code. It references the object that is executing the current function. If the function being referenced is a regular function, “this” references the global object.
The this keyword refers to the object the function belongs to, or the window object if the function belongs to no object. It's used in OOP code, to refer to the class/object the function belongs to For example: function foo() { this.
There is a way, although more expensive: throw an exception, catch it immediately, and dig out the first entry from its stack trace. See example here on how to parse the trace. The same trick can also be used in plain Java (if the code is compiled with debugging information turned on).
Edit: Apparently not all browsers support this. The good news is (thanks for the comment, Christoph!) that some browsers export source file name and line number directly through the fileName
and lineNumber
properties of the error object.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With