Is there a concise way to implement the following design pattern?
function a() {
function x() { /* code */ }
function y() { /* code */ }
/* more code */
x(); y(); // these can be called here
}
a();
a.x();
a.y();
I got acquainted with prototypes recently, and could probably use something like this:
a = function() { }
a.prototype.x = function() { }
a.prototype.y = function() { }
But maybe there’s a slimmer way? Since in my code a also belongs to something else’s prototype, i.e.
function plugin() { ... }
plugin.prototype.a = function () {}
plugin.prototype.a.prototype.x = function () {}
plugin.prototype.a.prototype.y = function () {}
You can write like that: