Let's say that I have a script like:
function foo(bar) {
return bar + 1;
}
var lorem = foo(1);
How can I modify the function so that I could use
1.foo() (or, I guess, in this case it'd have to be '1'.foo() ) instead of
foo(1)?
Note: the actual issue here is that I'm dealing with a third party script error:
foo.bar.getURL is not a function
foo.bar.isDefined is not a function
The only solution I can think of is to use typeof on my end to see if the functions exist, and if not then recreate them and simply return false. This sorta-kinda works:
if (typeof foo === 'undefined')
var foo = {};
if (typeof foo.bar === 'undefined')
foo.bar = [];
Object.prototype.isDefined = () => { return false; }
but it assumes that "foo.bar" will always be the variable name.
My theory is that if
foo.bar.isDefined can be made equivalent to
isDefined(foo) then I can avoid trying to recreate foo.bar.