Skip to content

Commit 42481af

Browse files
committed
Switched how methods should be written.
1 parent ca0f5ff commit 42481af

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -994,14 +994,14 @@
994994
995995
## <a name='constructors'>Constructors</a>
996996
997-
- Assign the constructors prototype as an object. This saves us some typing. Also, the extra level of indentation acts as an indication that you are working on the prototype and not instance methods.
997+
- Assign methods to the prototype object, instead of overwriting the prototype with a new object. Overwriting the prototype makes inheritance impossible: by resetting the prototype you'll overwrite the base!
998998

999999
```javascript
10001000
function Jedi() {
10011001
console.log('new jedi');
10021002
};
10031003
1004-
// bad
1004+
// good
10051005
Jedi.prototype.fight = function fight() {
10061006
console.log('fighting');
10071007
};
@@ -1010,7 +1010,7 @@
10101010
console.log('blocking');
10111011
};
10121012
1013-
// good
1013+
// bad
10141014
Jedi.prototype = {
10151015
fight: function fight() {
10161016
console.log('fighting');

0 commit comments

Comments
 (0)