Function Constructors and ‘.protype’ in javascript

Something Like that:
Function Constructors and '.protype'

JS

function Person(firstname, lastname){
    document.write(this + '<br>');
    this.firstname = firstname;
    this.lastname = lastname;
    document.write('This function is invoked.' + '<br>');
}

Person.prototype.getFullName = function(){
    return this.firstname + ' ' + this.lastname;
}

var john = new Person('Johan','de');
document.write(john + '<br>');

var jane = new Person('Jane','de');
document.write(jane + '<br>');

Person.prototype.getFormalFullName = function(){
    return this.lastname + ', ' + this.firstname;
}

document.write(john.getFormalFullName() + '<br>');

[codepen_embed height=”265″ theme_id=”0″ slug_hash=”JyLqOy” default_tab=”result” user=”pradeepanvi”]See the Pen Function Constructors and ‘.protype’ in javascript by Pradeep Kumar (@pradeepanvi) on CodePen.[/codepen_embed]

Now you can see

[object Object]
This function is invoked.
[object Object]
[object Object]
This function is invoked.
[object Object]
de, Johan

Leave a Reply

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