I'm currently working on a mobile HTML5/JS project, and I've just added a set of ~40 request 'classes' to the JS framework for more legible client->server communication. My boss has questioned the use of so many classes as he thinks we may encounter future issues with the number of variables and functions defined at once. My argument is that we should be writing for legibility first at the moment, and worry about optimization in the future when it becomes a problem.
So my question is, is this worry well-founded - is there a (fairly low) limit to the number of variables and functions that can be defined at once, and does this vary on a per-browser or per-device basis?
Edit:
An example of the request files is as follows, where JSONRequest is an 'extension' of AbstractRequest:
function MyServerRequest(content, info, otherData, callback, ignoreErrors) {
var requestData = new RequestData("MyServerRequest");
requestData.messageType = MyConst.MY_END_POINT;
requestData.message = {
something: content,
anotherthing: {
blah: info
}
thirdthing: otherData
};
JSONRequest.call(this, requestData, callback, ignoreErrors);
}
MyServerRequest.prototype = Object.create(JSONRequest.prototype);
MyServerRequest.prototype.constructor = MyServerRequest;
There is no hard limit on the number of variables or functions your JavaScript can contain, but you should be aware of file sizes and also beware of the possibility of accidentally naming two variables or functions the same thing.
If you have some functionality which will not be needed on all pages, you should split it into several JavaScript files and only include the ones which are needed.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With