If I create a trivial labeled statement such as:
foo: do { alert('hi') } while (false)
Is there any way to clone foo?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
No, apparently this is not possible. Labels cannot be used in an assignment statement and the scope of a label is the conditional block of the loop in which it is defined.
The closest alternative is a labelled function declaration in non-strict mode:
This can be used to create a declaration which is inaccessible:
but can be made accessible through string manipulation and the function constructor.
References
ECMAScript-6 Annex B, Section 3.2: Labelled Function Declarations
Loop unrolling and completion-values in es6
The JavaScript Goto
Speed up your JavaScript, Part 1