so I'm not entirely sure this is possible, but I am curious if it is possible to hack the definitions of "undefined" objects. Primarily, the purpose of this is to prevent errors from launching when doing a .replace on an object that is undefined. Is it possible to go into the "back end" (is there even such a thing??) and add a method to the undefined object (if that is even defined in the first place??). Essentially something along the likes of
undefined.prototype.replace = function(v,r){ return false };
Obviously this works with String or Object, but undefined, seems to, by nature, have no definition. But it feels like you should still be able to mess with it, since javascript has it as an available end result.
Thanks for your time! I'm really curious as to what will pop up here!
EDIT: The main issue is that I am co-developing with 8 other developers with versioning control, and some of the newer people that come in aren't familiar javascript (or good error handling for that matter), so I wanted to make a global handler for minute errors that can receive default returns if necessary. Doesn't look like this idea will work. Maybe a global try and catch scenario?
4.3.2 primitive value
member of one of the types Undefined, Null, Boolean, Number, or String as defined in Clause 8.
NOTE A primitive value is a datum that is represented directly at the lowest level of the language implementation.
4.3.10 Undefined type
type whose sole value is the undefined value.
As you can see undefined
is a primitive value, and as such you can't define properties to it. Because it's not an object. The best way to think of it is like null
. The only difference is that null
means intentional emptyness, while undefined
is a default value and type for those variables that are yet to be defined.