JS不高效代码示例(参数的传递)
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);
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步