Prev Demo
Adding Properties 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 properties 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; } person.native = "Madanapalli"; var myFriend = new person("Charitha", "Reddy", 23, "blue"); var myColleague = new person("Surendra", "Goud", 23, "brown"); document.getElementById("myId").innerHTML = "My friend is " + myFriend.native; </script> </body> </html>
Note: We DO NOT save your trial code in our database.
Output