Skip to content Skip to sidebar Skip to footer

Javascript: Prototype Attribute Not Visible On Parent

Example taken from here: http://sporto.github.io/blog/2013/02/22/a-plain-english-guide-to-javascript-prototypes/ I also asked a similar question here: Javascript: Added function do

Solution 1:

This is beceause Person is just a funtion(object)/Constructor:

Person =
function Person(name) {
    this.name = name;
}

To Get the kind object on person refer to the prototype

Person.prototype =
Person {kind: "person"}

Im not an expert in this but if you would want to create a new constructor you should overwrite the function.

You could see the function (below) as an constructor to set instance specific variables

    function Person(name) {
        this.name = name;
    }

Person.prototype.kind = 'person' is like a static variable on the class


Solution 2:

You are looking at the Person Constructor.

To look at the properties of the definition of a Person you can use Object.getOwnPropertyNames(Person.prototype)

This would show the kind property.


Post a Comment for "Javascript: Prototype Attribute Not Visible On Parent"