Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maximum number of var/function definitions in Javascript?

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;
like image 691
adamfsk Avatar asked Apr 29 '13 12:04

adamfsk


1 Answers

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.

like image 128
Glitch Desire Avatar answered Oct 16 '22 04:10

Glitch Desire