牛刀小试

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>

</body>
<script type="text/javascript">
    var life = {};
    for (life.age = 1; life.age < 3; life.age++) {
        switch (life.age) {
        case 1:
            life.say = function() {
                console.log(life.age+"hahaha");
            }
            break;

        case 2:
            life.say = function() {
            console.log(life.age);
            }
        case 3:
            life.say=function(){
            console.log(life.age+"hahah");
        }
            break;
        default:
            life.say=function(){
            console.log("hello,evenyOne");
        }
            break;
        }
        life.say();
    }
</script>
</html>

Insert title here

原文地址:https://www.cnblogs.com/javaweb2/p/6529042.html