X Tutup
Skip to content

Commit 2618a7e

Browse files
committed
update
1 parent 5a56f09 commit 2618a7e

File tree

1 file changed

+45
-21
lines changed

1 file changed

+45
-21
lines changed

OO/createObject.html

Lines changed: 45 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -58,37 +58,61 @@
5858

5959

6060
//【组合模式】
61-
function Person(name, age) {
62-
this.name = name;
63-
this.age = age;
64-
this.friends = ['Shelby', 'Court'];
65-
}
66-
67-
Person.prototype = {
68-
constructor: Person,
69-
sayName: function() {
70-
console.log(this.name);
71-
}
72-
};
73-
74-
var person1 = new Person('Nicholas', 29),
75-
person2 = new Person('Greg', 27);
76-
77-
person1.friends.push('Van');
78-
console.log(person1.friends);
79-
console.log(person2.friends);
80-
console.log(person1.friends === person2.friends); //false
81-
console.log(person1.sayName === person2.sayName); //true
61+
// function Person(name, age) {
62+
// this.name = name;
63+
// this.age = age;
64+
// this.friends = ['Shelby', 'Court'];
65+
// }
66+
67+
// Person.prototype = {
68+
// constructor: Person,
69+
// sayName: function() {
70+
// console.log(this.name);
71+
// }
72+
// };
73+
74+
// var person1 = new Person('Nicholas', 29),
75+
// person2 = new Person('Greg', 27);
76+
77+
// person1.friends.push('Van');
78+
// console.log(person1.friends);
79+
// console.log(person2.friends);
80+
// console.log(person1.friends === person2.friends); //false
81+
// console.log(person1.sayName === person2.sayName); //true
8282
//【组合模式】
8383

8484

8585

8686
//【动态原型模式】
87+
// function Person(name, age) {
88+
// this.name = name;
89+
// this.age = age;
90+
91+
// if (typeof this.sayName != 'function') {
92+
// Person.prototype.sayName = function() {
93+
// console.log(this.name);
94+
// }
95+
// }
96+
// }
8797
//【动态原型模式】
8898

8999

90100

91101
//【寄生构造函数模式】
102+
// function SpecialArray() {
103+
// var values = new Array();
104+
105+
// values.push.apply(values, arguments);
106+
107+
// values.toPipedString = function() {
108+
// return this.join('|');
109+
// };
110+
111+
// return values;
112+
// }
113+
114+
// var colors = new SpecialArray('red', 'blue', 'green');
115+
// console.log(colors.toPipedString());
92116
//【寄生构造函数模式】
93117

94118

0 commit comments

Comments
 (0)
X Tutup