My application has an api wrapper class originally created by typing it out in TypeScript and copying/pasting the javascript into my app.
So the class def looks like this:
var SiteApi = (function () {
function SiteApi(initially)
{
//stuff
}
SiteApi.prototype.method1 = function(){/*stuff*/};
SiteApi.prototype.method2 = function(){/*stuff*/};
return SiteApi;
})();
Now when they are on the admin page, I want to add an additional admin.js file that will contain admin methods. For example
SiteApi.prototype.Admin.method1 = function(){/*stuff*/};
I found an example that does the "end result" that I want:
// file main
function SomeObject() {
for (var i = 0, ii = SomeObject.Partial.length; i < ii; i++) {
SomeObject.Partial[i].apply(this, arguments);
}
}
SomeObject.Partial.SomeName = function() {
...
}
// file extra
SomeObject.Partial.SomeOtherName = function() {
...
}
(from: Is it possible to give javascript partial class behavior like C# or monkey patching like Ruby does?)
However, the type of class definition they are using is different.
How can I keep the TypeScript style class definition and yet do something similar to this example to add on the admin functions?
For reference, we use our class like so:
siteApi = new SiteApi();
So I imagine there will also need to be a line of code tying the admin functions into it.
Note, I'm Ok with using something like SiteApi.admin_method1
but the issue is that with TypeScript style classes the prototypes are defined in the definition and the object is executed, so it doesn't seem straightforward how to add in more prototypes later.