জাভাস্ক্রিপ্টে Object.create() মেথড দিয়ে এক্সিস্টিং অবজেক্টের নিজস্ব প্রোটোটাইপ তৈরি করা যায়। এই মেথড দিয়ে এক্সিস্টিং অবজেক্টের প্রপার্টিগুলো নতুন প্রোটোটাইপে ইনহেরিট করা যায়।
সিনট্যাক্স
Object.create(existingObject);
এই মেথড এক্সিস্টিং অবজেক্টকে নেয় এবং এর নিজস্ব প্রোটোটাইপ তৈরি করে যাতে প্রপার্টিগুলো ইনহেরিট হয় এক্সিস্টিং অবজেক্ট থেকে নতুন তৈরি প্রোটোটাইপে।
উদাহরণ
<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); // প্রোটোটাইপ তৈরি
newper.name = "sachin";
newper.profession = "cricketer";
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 cricketer sports
ব্যাখ্যা
Object.create(person) একটি নতুন অবজেক্ট তৈরি করে যার [[Prototype]] হলো person। newper-এ প্রপার্টি সেট করলে person প্রভাবিত হয় না (শ্যাডোইং)। newper.name অ্যাক্সেস করলে প্রথম নিজের প্রপার্টি চেক করে, না পেলে প্রোটোটাইপ চেইন ফলো করে person.name পায়। এটি প্রোটোটাইপাল ইনহেরিটেন্সের বেসিক উদাহরণ।