1

(from my code) I wonder the Person's prototype that gives inheritance for its child. I know that 'Programmer object(?)' inherit the Person's 'introduce' property. but I'm not sure that 'Programmer' inherit the Person's 'name' and 'age' property. In Chrome console, It looks that Programmer inherit the Person's 'name',,, But, In my memory, My teacher said that doesn't inherit the Person's 'name'property........

What is true???? (I can distinguish '[[prototype]]' and 'prototype property') But I'm not sure that what does engage in a prototype that something can inherit and what does not engage in prototype,

/////////////////////

in 
function X(){
    this.Z = null;
};
X.prototype.Y = null;

X's child inherit 'Y', but not Z

Is this right??

(Sorry I'm not a native English speaker,,,,)

//it's my code

<script>
        function Person(name, age){
            this.name = name;
            this.age =age;
        }
        Person.prototype.introduce = function(){
            console.log("My name is "+this.name);
        }


        function Programmer(){
            this.coding = function(){
                console.log("I can code up");
            }
        }

        Programmer.prototype = new Person("XX", 19);


    </script>
Tushar Gupta - curioustushar
  • 58,085
  • 24
  • 103
  • 107
  • It might be because [you're doing inheritance wrong](https://stackoverflow.com/questions/12592913/what-is-the-reason-to-use-the-new-keyword-here). Not all programmers are 19. Each `Programmer` instance should have its *own* name and age. – Bergi Jan 25 '19 at 18:50
  • Fire up jsfiddle and start experimenting ;) – Matthias Jan 25 '19 at 20:19

1 Answers1

0

A typical object inherits properties (including methods) from Object.prototype, although these properties may be shadowed (a.k.a. overridden).

Κωλζαρ
  • 803
  • 1
  • 10
  • 22