Take for example this "StartsWith" extension:
if (typeof String.prototype.startsWith != 'function') {
String.prototype.startsWith = function (str) {
return this.slice(0, str.length) == str;
};
}
If I was writing a web app, I would stick that code in an ExtensionMethods.js page that I imported on a web page within my site.
But what about the case of using this on the server with Node.js?
Thanks!
Since String is globally available, it can be placed in any file that gets required. When a file gets required, it gets executed.
You don't even need to export anything.