First look at the Code:
// Ajax follow/cancel function focus_action (UID, type) {var R; type = type? 'New': 'delete'; $. ajax ({URL: 'api/follow/'+ type, data: {'uid': uid}, datatype: 'json', type: 'post', async: false, success: function (e) {r = common_return (E );
Return R; // return is used here to end the function success: function. Instead of the end of the entire function focus_action. }); Return r; // here return is the end of the focus_action () function .} // Public return true/falsefunction common_return (e) {If (false = e) {return false;} else {return true ;}} alert (focus_action (1, 1 ));
Conclusion: In JS, pay attention to the use of return, which can terminate the running of the program. When using it, pay attention to its function scope: specifically, it plays a role in that function.
// The following is the conversion from: http://blog.sina.com.cn/s/blog_67aaf4440100p3zg.html
In the object-oriented programming syntax, we will encounter the break, continue, and return keywords. What are the specific operations for using these three keywords? When using these three keywords, what are the rules that need to be understood? Let's start with the introduction:
Break Statement of JS programming Syntax:
The break statement causes the running program to immediately exit the loop contained in the innermost layer or exit a switch statement.
Because it is used to exit a loop or switch statement, this form of break statement is valid only when it appears in these statements.
If the termination condition of a loop is very complex, it is much easier to use the break statement to implement certain conditions than to use a loop expression to express all the conditions.
For (VAR I = 1; I <= 10; I ++)
{
If (I = 6)
{
Break;
}
Document. Write (I );
}
When I = 6, directly exit the for loop. This loop will no longer be executed!
// Output result: 12345
JS programming Syntax:
The continue statement is similar to the break statement. The difference is that,Instead of exiting a loop, it starts a new iteration of the loop.
The continue statement can only be used in the loop body of the while statement, do/while statement, for statement, or for/in statement. It may cause errors when used elsewhere!
For (VAR I = 1; I <= 10; I ++)
{
If (I = 6) continue;
Document. Write (I );
}
When I = 6, it directly jumps out of this for loop. Continue the next execution.
// Output result: 1234578910
Return Statement of JS programming Syntax:
The return statement is used to specify the value returned by the function. The return statement can only appear in the function body. syntax errors may occur anywhere else in the code!
When the return statement is executed,Function execution stops even if there are other statements in the function body!
The use of the break, continue, and return commonly used keywords in JS programming syntax will be introduced to you here. I hope to understand and learn about break, continue, return is helpful for the use of the three common keywords.