码迷,mamicode.com
首页 > Web开发 > 详细

JS不高效代码示例(参数的传递)

时间:2016-04-17 10:14:22      阅读:129      评论:0      收藏:0      [点我收藏+]

标签:

    function Person1(firstName, lastName) {//无法推断参数的含义
        this.firstName = firstName;
        this.lastName = lastName;
        this.toString = function() {
            return this.firstName + " " + this.lastName;
        }
    }

    function Person2(attrs) {//可读性更好,可扩展性更好
        this.firstName = attrs["firstName"]
        this.lastName = attrs["lastName"];
        this.toString = function() {
            return this.firstName + " " + this.lastName;
        }
    }
    var p1 = new Person1("Frank", "Zammetti");
    var p2 = new Person2({
        "firstName" : "Frank",
        "lastName" : "Zammetti"
    });
    alert(p1);
    alert(p2);

 

JS不高效代码示例(参数的传递)

标签:

原文地址:http://www.cnblogs.com/feile/p/5400285.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!