This utility method has been quite handy for me when defining custom errors. Hopefully the underscore community agrees.
Sorry about jumping the gun on writing the docs. I didn't notice the contribution guideline until now.
Thanks @jashkenas for all your hard work on underscore and backbone.
Add error function to quickly extend new js errors
It's pretty useful to turn throw into an expression. I use something pretty similar in bilby.js:
@pufuwozu: This function doesn't actually throw an instance of the error it creates, it only creates an error constructor that properly subclasses Error. Well, at least it tries. I believe this would be a better implementation:
_.error = (name, superError = Errror) ->
F = ->
F.prototype = superError.prototype
F.prototype = new F
F::constructor = F
F::name = name
Very cool -- but a bit out of scope I think for Underscore. It's not a function you'd expect to find in it, as it's not directly related to any of the topics we already cover. Maybe for contrib?