Getting a JSLint warning concerning labels in Javascript

De openkb
Aller à : Navigation, rechercher

Sommaire

Questions

In my javascript I have this

    loopDeLoop:
        while (foo !== bar) {
            switch (fubar) {
                case reallyFubar:
                    if (anotherFoo == anotherBar) {
                        break loopDeLoop;
                    }
                    break;
                default:
                    break;
            }
        }

But JSLint says... lint warning: use of label

http://www.jslint.com/lint.html http://www.jslint.com/lint.html

Labels
JavaScript allows any statement to have a label, and labels have a separate name space. JSLint is more strict. JSLint expects labels only on statements that interact with break: switch, while, do, and for. JSLint expects that labels will be distinct from vars and parameters.

How do I construct the above to get rid of the warning?

Thanks,
Greg

Answers

You are using the label correctly.

JSLint is throwing a warning because labels in Javascript are horribly bad style, and JSLint wants you to know that.

To reiterate, if you use labels at all, even correctly, JSLint will give that warning.

Edit: Looks like you might be able to disable the label warning with a -use_of_label configuration directive.

Source

License : cc by-sa 3.0

http://stackoverflow.com/questions/381580/getting-a-jslint-warning-concerning-labels-in-javascript

Related

Outils personnels
Espaces de noms

Variantes
Actions
Navigation
Outils