Correction status:Uncorrected
Teacher's comments:
JavaScript有两种创建对象的方式:字面量或构造函数。
示例代码如下:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> <script> // 一、构造函数创建对象 let team1=new Object(); team1.name='76ers'; team1.addr='PHI'; team1.say=function () { return '大家好,我们是'+this.name+'队,我们的城市是'+this.addr; } console.log(team1.say()); //二、字面量函数创建对象 let team2={ name:'lakers', addr:'LA', say:function () { return '大家好,我们是'+this.name+'队,我们的城市是'+this.addr; } } console.log(team2.say()); </script> </head> <body> </body> </html>
点击 "运行实例" 按钮查看在线实例