Correction status:qualified
Teacher's comments:
<!DOCTYPE HTML> <html> <head> <title>js创建对象的方式</title> <script> //基于基础对象创建 let obj = new object(); let obj = {}; obj.name='小花' obj.sex='女' obj.date =1992 obj.getInfo=function (){return 2018-this.date}; console.log(obj.name); console.log(obj.sex); console.log(obj.getInfo()); //构造函数 function Student(name,age,sex){ this.name= name; this.age=age; this.sex=sex; } Student.prototype.getinfo=function (){ return this.name; } s1 = new Student('小花','18','男'); console.log(s1.getinfo()); </script> </head> <body> </body> </html>
点击 "运行实例" 按钮查看在线实例
感悟:javascript对象的创建有三个方法:1.let obj={}创建一个空对象。2.let obj=new object();基于原始对象创建,这样会继承原始对象的方法。3.通过构造方法创建