Take the 2-minute tour ×
Code Review Stack Exchange is a question and answer site for peer programmer code reviews. It's 100% free, no registration required.

I have on object like this

initialize : {  
    method : function() {
        this.__. //--> do another thing
        ... //--> so many
        this.__.params. //--> do another thing
        ... //--> so many
    }           
}

and the method of this object call by another function. as you see we are have many lines that refer to this.__ and this.__.params and for prevent this I declare local variable T and P like below

initialize : {  
    method : function() {
        var T = this.__, P = T.params;
        T. //--> do another thing
        ... //--> so many
        P. //--> do another thing
        ... //--> so many
    }           
}

as I mentioned before the method calls by another function called caller.

I'm wondering that if possible I don't declare locale variable in the method function and instead define it in scope of caller function and pass it to the method ?

Thanks.

share|improve this question
1  
If I understand correctly, you have another object which is calling method as if it were its own method (and therefore this references the other object). I'm assuming that since you're trying to simplify this bit of code, it's a user-extendable part of some library. I don't really see any problem with it as-is (except for the __ name, which is a bit odd). I guess I'd need more context to know why you want to simplify it. You certainly shouldn't have the caller define the variables for you (which is impossible anyway), but I don't see why you can't just use normal parameters? –  Dave Oct 13 '13 at 11:58
 
If you can tell us what this and this.__ is, maybe we can provide another approach. –  Joseph the Dreamer Oct 13 '13 at 12:07
 
Thanks, in fact I just write a framework base on aspect oriented programming for the developers and it's include a lot of components and I try to simplify it, for example I told the developers that follow as example number two because it reduces the code size that must be send from server to client (because of the problem of bandwidth), and after a while I thought if is it possible to declare locale variable in another scope and pass it to another scope. anyway Thanks for you help. –  AKZ Oct 13 '13 at 12:18
 
If you set up your server to gzip resources (which you should), this isn't an issue anyway. Also you should be minifying your scripts before publishing them (e.g. using the closure compiler). I would still suggest that parameters are the way to go (if not what you already have), and you shouldn't put a lot of effort into saving 10 characters. –  Dave Oct 13 '13 at 12:21
add comment

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.