Prev Demo
Adding Methods To A 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 methods to a 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; this.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