File tree Expand file tree Collapse file tree 1 file changed +5
-2
lines changed
Expand file tree Collapse file tree 1 file changed +5
-2
lines changed Original file line number Diff line number Diff line change 3939Person . prototype . getName = function ( ) {
4040return this . name ;
4141} ;
42+
4243// create a new person
4344var papa = new Person ( ) ;
45+
4446// inherit
4547var kid = object ( papa ) ;
48+
4649// test that both the own property
4750// and the prototype property were inherited
4851console . log ( kid . getName ( ) ) ; // "Adam"
4952
50-
5153// parent constructor
5254function Person ( ) {
5355// an "own" property
5456this . name = "Adam" ;
5557}
58+
5659// a property added to the prototype
5760Person . prototype . getName = function ( ) {
5861return this . name ;
5962} ;
63+
6064// inherit
6165var kid = object ( Person . prototype ) ;
6266console . log ( typeof kid . getName ) ; // "function", because it was in the prototype
6367console . log ( typeof kid . name ) ; // "undefined", because only the prototype was inherited
6468
65-
6669/* Addition to ECMAScript 5 */
6770var child = Object . create ( parent ) ;
6871
You can’t perform that action at this time.
0 commit comments