X Tutup
Skip to content

Commit aa2dbca

Browse files
committed
update
1 parent df259af commit aa2dbca

File tree

2 files changed

+32
-30
lines changed

2 files changed

+32
-30
lines changed

OO/createObject.html

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -155,29 +155,29 @@
155155

156156

157157
//【动态原型模式】
158-
// function Person(name, age) {
159-
// this.name = name;
160-
// this.age = age;
161-
162-
// if (typeof this.sayName == 'function') return;
163-
// // console.log('create');
164-
// Person.prototype.sayName = function() {
165-
// console.log(this.name);
166-
// }
167-
168-
// Person.prototype.sayAge = function() {
169-
// console.log(this.age);
170-
// }
171-
// }
158+
function Person(name, age) {
159+
this.name = name;
160+
this.age = age;
161+
162+
if (typeof this.sayName == 'function') return;
163+
// console.log('create');
164+
Person.prototype.sayName = function() {
165+
console.log(this.name);
166+
}
167+
168+
Person.prototype.sayAge = function() {
169+
console.log(this.age);
170+
}
171+
}
172172

173-
// var person1 = new Person('xyx', 123),
174-
// person2 = new Person('yyy', 456);
173+
var person1 = new Person('xyx', 123),
174+
person2 = new Person('yyy', 456);
175175

176-
// console.log(person1);
177-
// console.log(person2);
176+
console.log(person1);
177+
console.log(person2);
178178

179-
// person1.sayName();
180-
// person2.sayAge();
179+
person1.sayName();
180+
person2.sayAge();
181181

182182
//动态原型模式问题
183183
//动态原型模式实际是是对组合模式进行了一次包装,将对原型对象的初始化操作放入构造函数内部了。
@@ -228,20 +228,20 @@
228228

229229

230230
//【稳妥构造函数模式】
231-
function Person(name, age) {
232-
var o = new Object();
231+
// function Person(name, age) {
232+
// var o = new Object();
233233

234-
//可以定义些私有变量
234+
// //可以定义些私有变量
235235

236-
o.sayName = function() {
237-
console.log(name);
238-
};
236+
// o.sayName = function() {
237+
// console.log(name);
238+
// };
239239

240-
return o;
241-
}
240+
// return o;
241+
// }
242242

243-
var friend = Person('Nicholas', 29);
244-
friend.sayName();
243+
// var friend = Person('Nicholas', 29);
244+
// friend.sayName();
245245

246246
//稳妥构造函数问题
247247
//稳妥对象是指没有公共属性,而且其方法也不引用 this 的对象。

OO/inherit.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,8 @@
182182

183183
//【寄生式继承】
184184

185+
186+
185187
//【寄生组合式继承】
186188
// function inheritPrototype(subType, superType) {
187189
// var prototype = Object.create(superType.prototype);

0 commit comments

Comments
 (0)
X Tutup