lundi 11 mai 2015

Is it ok to declare an object to be equal to itself in Javascript for the sake of refactoring a large project

I'm working on a very large javascript web app that doesn't really have a method to it. There seems to be an attempt to declare everything as part of a master object called "app". The original program existed as a single app.js file over 300k lines of code where the following was declared:

var app = {};

Beyond that everything in the app is written as such.

app.somefunction = function(args, callback) { 
    some code
};

This apparently allowed for the author to handily use Eclipse IDE "outline", which I confess I have started to enjoy having, never previously having been an IDE user I'm becoming a convert to the niceties they provide.

My question is, as I work on a phased refactor of this huge codebase, potentially trying to merge it into some sort of more established framework perhaps using something like require.js, is it OK to split the "app.js" up into smaller files and for the sake of sanity to be able to use the IDE outline declare app to be equal to itself in each one.

app = app;

I've tested this, it works from what I can tell and it allows the IDE to add all the subsequent functions to the outline window while making the project a little more manageable while I learn what it is actually doing. Are there any drawbacks to doing this? I imagine some async loading issues might occur; this could possibly add to client side overhead; or is this perfectly acceptable?

I realize that this is sort of a code philosophy question, but the simple Q&A would be, what effect would app=app; have?

Aucun commentaire:

Enregistrer un commentaire