So, as a work requirement our code cannot be larger than 80 columns and 250 rows. This means I have to go back and break up my code into smaller files and I am exploring a few options. First that came to mind was prototyping
with JavaScript since I can't install RequireJS
. Secondly, my application uses a closure. My question is this: can you prototype into a closure? Example below.
File #1
var app = (function () {
var _userName = "Steve";
function sayHello() {
return "Hello " + _userName;
}
return {
sayHello: sayHello
}
})();
File #2
app.prototype.sayGoodbye = function() {
return "Goodbye " + _userName;
};
Output
app.sayHello(); // should output "Hello Steve"
app.sayGoodbye(); // should output "Goodbye Steve"
However this does not seem to work, because the sayGoodbye()
function is not included in the closure. But, if told the sayHello()
function to use the sayGoodbye()
, that also does not work. Any suggestions on how to construct a closure object across multiple files? Thanks!