# magicTower **Repository Path**: mcxiang/magicTower ## Basic Information - **Project Name**: magicTower - **Description**: No description available - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2019-08-08 - **Last Updated**: 2020-12-19 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # myCourse 2.向对象 1.1 function Person() { this.name = 1; return {}; } var person = new Person(); console.log('name:', person.name); //返回undefind Person里return的是空对象 里面没有name属性 1.2 function Person() { this.name = 1; } Person.prototype = { show: function () { console.log('name is:', this.name); } }; var person = new Person(); person.show(); //返回1 new关键字创建的新对象继承了父对象的那么属性 1.3 function Person() { this.name = 1; } Person.prototype = { name: 2, show: function () { console.log('name is:', this.name); } }; var person = new Person(); Person.prototype.show = function () { console.log('new show'); }; person.show(); //返回'new show' 父类上的show方法被修改 1.4 function Person() { this.name = 1; } Person.prototype = { name: 2, show: function () { console.log('name is:', this.name); } }; var person = new Person(); var person2 = new Person(); person.show = function () { console.log('new show'); }; person2.show(); //返回name is:1 this.name大于prototype的优先级??? person.show(); //返回'new show' person的show方法被修改 2、综合题 function Person() { this.name = 1; } Person.prototype = { name: 2, show: function () { console.log('name is:', this.name); } }; Person.prototype.show(); //返回2 调用了Person.prototype的show方法 (new Person()).show(); //返回1 同this.name大于prototype的优先级???