首页 > 代码库 > Jumps

Jumps

labeled statements:

mainloop: while(token != null) {    // Code omitted...    continue mainloop;  // Jump to the next iteration of the named loop    // More code omitted...}

break:

the break statement, used alone, cause the innermost enclosing loop or switch statement to exit immediately

for(var i = 0; i < a.length; i++) {    if (a[i] == target) break;}

  

break labelname;

continue:

the continue statement is similar to the break statement. Instead of exiting a loop, however, continue restart the loop at the next iteration. 

The continue statement, in both its labeled and unlabeled forms, can be only used within the body of a loop.

for(i = 0; i < data.length; i++) {    if (!data[i]) continue;  // Can‘t proceed with undefined data    total += data[i];}

return:

A return statement may appear only within  the body of function. It is a syntax error for it to appear anywhere else.

throw:

function factorial(x) {    // If the input argument is invalid, throw an exception!    if (x < 0) throw new Error("x must not be negative");    // Otherwise, compute a value and return normally    for(var f = 1; x > 1; f *= x, x--) /* empty */ ;    return f;}

try/catch/finally:

try and finally can be used together without a catch clause.

try {  // Normally, this code runs from the top of the block to the bottom  // without problems. But it can sometimes throw an exception,  // either directly, with a throw statement, or indirectly, by calling  // a method that throws an exception.}catch (e) {  // The statements in this block are executed if, and only if, the try  // block throws an exception. These statements can use the local variable  // e to refer to the Error object or other value that was thrown.  // This block may handle the exception somehow, may ignore the  // exception by doing nothing, or may rethrow the exception with throw.}finally {  // This block contains statements that are always executed, regardless of  // what happens in the try block. They are executed whether the try  // block terminates:  //   1) normally, after reaching the bottom of the block  //   2) because of a break, continue, or return statement  //   3) with an exception that is handled by a catch clause above  //   4) with an uncaught exception that is still propagating}

miscellaneous statements:

with (object)    statement

this statement add object to the front of the scope chain, executes statement, and then restores the scope chain to its original state.

The common use of the with statement is to make it easier to work with deeply nested object hierarchies,like:

document.forms[0].address.value

If you need to write expressions like this a number of times, you can use the with statements to add the form object to the scope chain:

with(document.forms[0]) {    // Access form elements directly here. For example:    name.valuehttp://www.mamicode.com/= "";    address.valuehttp://www.mamicode.com/= "";    email.valuehttp://www.mamicode.com/= "";}

you can avoid the with statement like this:

var f = document.forms[0];f.name.valuehttp://www.mamicode.com/= "";f.address.valuehttp://www.mamicode.com/= "";f.email.valuehttp://www.mamicode.com/= "";

debugger:

use strict:

 

 

  

Jumps