zoukankan      html  css  js  c++  java
  • javascript 终止函数执行操作

    1、如果终止一个函数的用return即可,实例如下:
    function testA(){
        alert('a');
        alert('b');
        alert('c');
    }
    testA(); 程序执行会依次弹出'a','b','c'。

    function testA(){
        alert('a');
        return;
        alert('b');
        alert('c');
    }
    testA(); 程序执行弹出'a'便会终止。

    2、在函数中调用别的函数,在被调用函数终止的同时也希望调用的函数终止,实例如下:
    function testC(){
        alert('c');
        return;
        alert('cc');
    }

    function testD(){
        testC();
        alert('d');
    }
    testD(); 我们看到在testD中调用了testC,在testC中想通过return把testD也终止了,事与愿违return只终止了testC,程序执行会依次弹出'c','d'。

    function testC(){
        alert('c');
        return false;
        alert('cc');
    }

    function testD(){
        if(!testC()) return;
        alert('d');
    }
    testD(); 两个函数做了修改,testC中返回false,testD中对testC的返回值做了判断,这样终止testC的同时也能将testD终止,程序执行弹出'c'便会终止。

  • 相关阅读:
    循环语句
    JAVA-数据类型、变量、常量
    JAVA——程序流程控制——循环语句——for循环(打印三角形)
    循环语句
    JAVA基础学习1
    新手上路
    mysql内置函数之事务
    mysql内置功能
    mysql内置函数之视图
    pymysql模块
  • 原文地址:https://www.cnblogs.com/caroline4lc/p/4412924.html
Copyright © 2011-2022 走看看