对象字面量是向函数传递大量可选参数的首选方式

2017-06-15 18:29:00
admin
原创
443
<!DOCTYPE html>
<html>
<head>
    <title>Object Type Example 4</title>
    <script type="text/javascript">
        function displayInfo(args) {
            var output = "";
        
            if (typeof args.name == "string"){
                output += "Name: " + args.name + "\n";
            }
        
            if (typeof args.age == "number") {
                output += "Age: " + args.age + "\n";
            }
        
            alert(output);
        }
        
        displayInfo({ 
            name: "Nicholas", 
            age: 29
        });
        
        displayInfo({
            name: "Greg"
        });


    </script>
</head>
<body>

</body>
</html>
  • QQ讨论群
  • 关注微信
    • 欢迎咨询
    • 欢迎加入QQ群 16506021
  • 公众号:源宝网络