हम मौजूदा ऑब्जेक्ट तक पहुंचने में सक्षम हैं "Object.create() . नामक जावास्क्रिप्ट विधि का उपयोग करके अपना स्वयं का प्रोटोटाइप बनाकर t "। इस पद्धति का उपयोग करके हम मौजूदा गुणों से गुणों को नए बनाए गए प्रोटोटाइप में प्राप्त कर सकते हैं। आइए इसकी संक्षेप में चर्चा करें।
वाक्यविन्यास
Object.create(existing obj);
यह विधि मौजूदा वस्तु को लेती है और अपना स्वयं का प्रोटोटाइप बनाती है ताकि गुण विरासत में मिले मौजूदा वस्तु . से नए निर्मित प्रोटोटाइप . के लिए ।
उदाहरण
निम्न उदाहरण में, प्रारंभ में, "व्यक्ति . नाम की एक वस्तु " बनाया गया है और "Object.create . का उपयोग करके बनाया गया है " इसका स्वयं का प्रोटोटाइप एक चर "नया . बनाया और असाइन किया गया है "। बाद में, प्रोटोटाइप का उपयोग करके मौजूदा ऑब्जेक्ट की वस्तुओं को बदल दिया गया है और नए गुणों को आउटपुट में दिखाया गया है।
<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> आउटपुट
Karthee Actor Tamil Using a prototype the properties of the existing object have been changed to the following sachin crickter sports