Trying to understand why the two cross-browser properties of Javascript Error object, namely "name" and "message", can't be found using the "for ... in" method
// error code
...
}catch( err ){
// in FF this lists 3 properties for fileName, lineNumber and columnNumber...
// but NOT name or message!
for(var propertyName in err) {
$( '#diags' ).append( 'err property: ' + propertyName + ',
value: ' + err[ propertyName ] + '<br>' );
}
// this line prints fine:
$( '#diags' ).append( 'Error - name:' + err.name + ', message: ' + err.message + '<br>' );
}
Edit
I am asked what is name and message. These are properties (are they though?) which all Errors have in any browser... so in the above code I have added an extra line of code which shows that these "attributes" or whatever they are print fine
Edit2
Following Mati's helpful answer I did a bit of searching. This seems to answer the "inspection" question: Is it possible to get the non-enumerable inherited property names of an object?
name
ormessage
? – Beware.message
property. Anything else is proprietary. This article shows how the Error object can be standardized - see section titled "Custom Error Types". – Upspring