I know this is frowned upon, I was just exploring the idea and for the life of me cannot seem to make this work the way I would want it too.
The example should explain all:
String.prototype.MyNS = function() {}
String.prototype.MyNS.fooify = function() {
return this + 'foo!';
}
var theString = 'Kung';
alert(theString.MyNS.fooify());
Of course this simply append the function definition to ‘foo’ … adding this() instead doesnt work.
I understand that I have lost context in there but cannot figure out how to cause the original to fire off and give me what I want.
Here’s one way you could do it:
See it in action on jsFiddle
Note, as slashingweapon points out, that you will have to call it like so:
As far as I know, there’s no cross-browser way to do it without having to call
MyNSas a function.