Prev Demo
Adding New Methods To Existing Prototype In Javascript Object-Oriented Programming
Next Demo
Write code here
J
|
B
|
A
<!DOCTYPE html> <html> <head> <title>Demo</title> </head> <body> <h1>Adding new methods to existing prototype</h1> <p id="myId"></p> <script> function person(first, last, age, eye) { this.firstName = first; this.lastName = last; this.age = age; this.eyeColor = eye; } person.prototype.name = function () { return this.firstName + " " + this.lastName }; var myFriend = new person("Charitha", "Reddy", 23, "blue"); document.getElementById("myId").innerHTML = "My friend is " + myFriend.name(); </script> </body> </html>
Note: We DO NOT save your trial code in our database.
Output