简体   繁体   English

关于 JavaScript 的原型概念

[英]about prototype concept of JavaScript

(from my code) I wonder the Person's prototype that gives inheritance for its child. (从我的代码)我想知道为它的孩子提供继承的 Person 的原型。 I know that 'Programmer object(?)' inherit the Person's 'introduce' property.我知道 'Programmer object(?)' 继承了 Person 的 'introduce' 属性。 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........在 Chrome 控制台中,看起来 Programmer 继承了 Person 的 'name',,,, 但是,在我的记忆中,我的老师说不继承 Person 的 'name' 属性......

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, (我可以区分'[[prototype]]'和'prototype property')但是我不确定什么搞原型可以继承,什么不搞原型,

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

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

X's child inherit 'Y', but not Z X 的孩子继承“Y”,但不继承 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>

一个典型的对象从 Object.prototype 继承属性(包括方法),尽管这些属性可能被隐藏(又名覆盖)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM