- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to access a JavaScript object using its own prototype?
We can able to access the existing object by creating its own prototype using a javascript method called "Object.create()". Using this method we can inherit the properties from the existing properties to the newly created prototype. Let's discuss it in a nutshell.
syntax
Object.create(existing obj);
This method takes the existing object and creates its own prototype so that the properties will be inherited from the existing object to the newly created prototype.
Example
In the following example, Initially, an object named "person" is created and the using "Object.create" its own prototype is created and assigned to a variable "newper". Later on, using the prototype the objects of the existing object have been changed and the new properties were displayed as shown in the output.
<html> <body> <script> var person = { name: "Karthee", profession : "Actor", industry: "Tamil" }; document.write(person.name); document.write("</br>"); document.write(person.profession); document.write("</br>"); document.write(person.industry); document.write("</br>"); document.write("Using a prototype the properties of the existing object have been changed to the following"); document.write("</br>"); var newper = Object.create(person); /// creating prototype newper.name = "sachin"; newper.profession = "crickter"; newper.industry = "sports"; document.write(newper.name); document.write("</br>"); document.write(newper.profession); document.write("</br>"); document.write(newper.industry); </script> </body> </html>
Output
Karthee Actor Tamil Using a prototype the properties of the existing object have been changed to the following sachin crickter sports
- Related Articles
- How to create an object with prototype in JavaScript?
- How to access cookies using document object in JavaScript?
- How to create an object and access its properties in JavaScript?
- How to access an object value using variable key in JavaScript?
- How to access the first value of an object using JavaScript?
- How to add, access JavaScript object methods?
- How to access an object through another object in JavaScript?
- How to add, access, delete, JavaScript object properties?
- How to access an object having spaces in the object’s key using JavaScript?
- Adding a function for swapping cases to the prototype object of strings - JavaScript
- How does JavaScript .prototype work?
- How to Access element from Table using JavaScript?
- Accessing variables in a constructor function using a prototype method with JavaScript?
- JavaScript Array prototype Constructor
- JavaScript String Prototype Property

Advertisements