You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Jan 21, 2024. It is now read-only.
I came up with a clever technique a few months ago that I wanted to try out... turns out to be a win but only in Firefox (so far as I've seen): http://jsfiddle.net/JamesMGreene/MYgpY/
Basically you override the Error.prototype.toString method to store a reference to that Error so that you can access it again during the window.onerror handler even if the 5th error argument does not exist. This works on the notion that the browsers would invoke the toString (or valueOf) method when getting the string to pass as the 1st message argument to window.onerror; however, it turns out that this assumption is only currently valid in Firefox (as far as major browsers go, anyway)... the others seem to utilize some internal conversion approach instead. Either way, it's easy to feature test and can be a big win in Firefox.
The text was updated successfully, but these errors were encountered:
P.S. This obviously doesn't work on any custom Error types that override the toString method but I've found it very useful all the same. If they are your own Error types, you can utilize this same technique in the class's own toString method — Firefox will still call it even if it's not at the Error.prototype.toString level.
I came up with a clever technique a few months ago that I wanted to try out... turns out to be a win but only in Firefox (so far as I've seen):
http://jsfiddle.net/JamesMGreene/MYgpY/
Basically you override the
Error.prototype.toString
method to store a reference to thatError
so that you can access it again during thewindow.onerror
handler even if the 5therror
argument does not exist. This works on the notion that the browsers would invoke thetoString
(orvalueOf
) method when getting the string to pass as the 1stmessage
argument towindow.onerror
; however, it turns out that this assumption is only currently valid in Firefox (as far as major browsers go, anyway)... the others seem to utilize some internal conversion approach instead. Either way, it's easy to feature test and can be a big win in Firefox.The text was updated successfully, but these errors were encountered: