企业🤖AI智能体构建引擎,智能编排和调试,一键部署,支持知识库和私有化部署方案 广告
# 即使对象初始化 ```javascript /* var obj = { name:"默认", age:"默认", showName:function(){ console.log("姓名:" + this.name); }, showAge:function(){ console.log("年龄:" + this.age); }, init:function(name,age){ this.name = name; this.age = age; } } obj.init("zs",18); console.log(obj.name); console.log(obj.age); */ // 优化 初始化只执行一次 ({ name:"默认", age:"默认", showName:function(){ console.log("姓名:" + this.name); }, showAge:function(){ console.log("年龄:" + this.age); }, init:function(name,age){ this.name = name; this.age = age; this.showName(); this.showAge(); } }).init("zs",18); ```