Object.create and Pure Prototypal Inheritance in javascript

Something Like that:
Object.create and Pure Prototypal Inheritance

For that you need to create first html code.

HTML

<p id="demo"></p>

After that add this JS code.

JS

var person = {
    firstname: 'Default',
    lastname: 'Default',
    greet: function(){
        return 'Hi' + this.firstname;
    }
}

var john = Object.create(person);
john.firstname = 'John';
john.lastname = 'Doe';
document.getElementById('demo').innerHTML = john;

[codepen_embed height=”265″ theme_id=”0″ slug_hash=”EvRZWw” default_tab=”result” user=”pradeepanvi”]See the Pen Object.create and Pure Prototypal Inheritance in javascript by Pradeep Kumar (@pradeepanvi) on CodePen.[/codepen_embed]

Now you can see

[object Object]

Leave a Reply

Your email address will not be published. Required fields are marked *