A middleware script that seeks to allow functions in local javascript to be automatically wrapped in custom code wrappers. These can then be used to aid profiling/error checking/code understanding.
GNU General Public License v2.0
4
stars
1
forks
source link
Depreciate Object.infect for method that must be passed object? #16
var x = null;
x.infect(); //cannot call method of null object
This breaks the promise that infections can be run safely on any Javascript variable, and is true for both undefined and null. One solution would be to call infect through a more straightforward means.
var x = null;
Object.infect(x); //no error.
This is basically the only chance to do a change like this - once an API is completely finalized, I won't really be able to break compatibility in the same way, so this is worth considering for that reason alone.
Pros:
The call is harder to break, fitting with the theme of being able to call infect basically everywhere in your code without thinking about it.
Gives a more permanent resolution to #14, since properties are no longer being referenced via this
Cons:
No longer thematically consistent (Infect is something you do on and object, not something that happens around one)
Typing is longer, no quick access through the object itself.
Possible resolutions:
Go with either method
Support both
infect can optionally take a parameter as an object to infect instead of this.
var x = {}; x.infect(x); is frankly a weird syntax to support.
This breaks the promise that infections can be run safely on any Javascript variable, and is true for both
undefined
andnull
. One solution would be to call infect through a more straightforward means.This is basically the only chance to do a change like this - once an API is completely finalized, I won't really be able to break compatibility in the same way, so this is worth considering for that reason alone.
Pros:
this
Cons:
Possible resolutions:
infect
can optionally take a parameter as an object to infect instead ofthis
.var x = {}; x.infect(x);
is frankly a weird syntax to support.