Reputation: 140
I'm curious if there is a way to get the name of the referenced object from a caught ReferenceError. For example:
try{
foo;
} catch(e){
e.message; // "ReferenceError: foo is not defined"
}
Is there another property holding "foo"? I'd like to create something like missing_method in ruby if it's possible. Except for variable access, so I'm not concerned about losing args/context. This seems to be one of the big blockers.
Upvotes: 4
Views: 493
Reputation: 44609
Good question, in my knowledge (and if you check a console) there's no property/method in the ReferenceError object referring to the missing name.
You could parse the error message to extract the property name. But that'd be hard as error messages can be localized and different depending on the browser used. Although, if you want to use this for development and you control the environment, it should be fairly easy to implement with a Regexp.
Upvotes: 1