创建对象之动态原型模式
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title></title> </head> <body> <script type="text/javascript"> //创建对象之动态原型模式 function Person(name , age , job){ this.name = name; this.age = age; this.job = job; //判断是否存在 if( typeof this.sayName != 'function'){ Person.prototype.sayName = function(){ console.log(this.name); } } } var person1 = new Person("宝清老家" , 29 , "Software"); person1.sayName(); </script> </body> </html>