I'm slowly working my way to understanding the subtleties of JavaScript. At this time, I'm trying to instantiate an instance of the JavaScript Error object. I know that I can do the following:
var error = new Error('The value is invalid');
error.name = 'ArgumentException';
throw error;
However, I'm trying to figure out/understand if there's a way to condense this instantiation down to a single line. For instance, I'd like to do something like the following:
var error = new Error().{ message:'The value is invalid', name:'ArgumentException'};
throw error;
Is it possible to instantiate an instance of the JavaScript Error object while setting both the message and name properties?
Thank you!
nameproperty is inherited fromFunction, so you can't set it directly when instanciating anErrorobject as far as I know.throw (function() { var e = new Error("Whoops!"); e.name = 'ArgumentException'; return e; })();