Open tao-cumplido opened 6 years ago
I figured out why it doesn't work, I didn't know that map
receives an optional second argument to be used as this
so when used like this it works:
errors.map(ErrorStackParser.parse, ErrorStackParser).forEach(console.log)
I think the changes to the code would be minimal to support the use case without passing the thisArg
. Something like this:
function ErrorStackParser$$parse(error) {
// ...
}
// other methods
return {
parse: ErrorStackParser$$parse
}
I agree with you @tao-cumplido. As far as I understand, ErrorStackParser
is meant to be used as a singleton like e.g. the Math
object,
so I think its methods should be independant of the this
binding.
This could also be done using .bind()
to ensure the this
binding inside parse()
always refer to ErrorStackParser
:
// ...
parse: function ErrorStackParser$$parse(error) {
// ... code
}.bind(ErrorStackParser),
However .bind()
is not supported in old environments.
I have an array of errors which I want to convert with error-stack-parser. What I did was basically this:
Expected Behavior
I expected to get an array of StackFrames for each error.
Current Behavior
Steps to Reproduce (for bugs)
This works:
And surprisingly this works too:
Your Environment
error-stack-parser 2.0.1 Node.js 8.9.0 Windows 10