3

At the top of my script I two variables holding two selectors:

    var all_open = $('ul#festival_dates li.controls a:eq(0)');
    var all_close = $('ul#festival_dates li.controls a:eq(1)');

I'm getting there with Jquery, I'm now at the point where I'm looking at my code and finding ways to write much more efficient scripts. One thing I noticed using YUI Compressor is that it said "[WARNING] Try to use a single 'var' statement per scope." and highlighted the two lines above, has anyone got any suggestions about this, or can explain a more technical description of what this means?

Any help would be much appreciated.

Thank you for your replie.

2 Answers 2

8

What it' saying is this:

var all_open = $('ul#festival_dates li.controls a:eq(0)'),
    all_close = $('ul#festival_dates li.controls a:eq(1)');

to use the comma operator.

As for performance, http://jsperf.com/single-var, I'm not sure it makes much of a difference.

Sign up to request clarification or add additional context in comments.

Comments

2

Instead of repeating the word var you can use commas to delimit additional variable declarations:

var all_open = $('ul#festival_dates li.controls a:eq(0)'),
all_close = $('ul#festival_dates li.controls a:eq(1)');

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.