function Person(first, last, age, gender, interests) {
this.name = {
first,
last
};
this.age = age;
this.gender = gender;
this.interests = interests;
};
Person.prototype.greeting = function() {
alert('Hi! I\'m ' + this.name.first + '.');
};
//
function Teacher(first, last, age, gender, interests, subject) {
Person.call(this, first, last, age, gender, interests);
this.subject = subject;
}
//console.log("Person",Person)
var personobj= new Person("A","B",23,"Male","Love");
Teacher.prototype = Object.create(Person.prototype);//before this line only object properties and ethods(constructor function) are copied to Teacher , To inherit prototype of PERSON into TEACHER we have to write this line.
Teacher.prototype.constructor = Teacher;//in the prevoiUs line as we assigned PERSON prototype to TEACHER, TEACHER constructor property is now equal to Person(). THEN WE NEED to correctly assign it correctly using this line.
Teacher.prototype.greeting = function() {}
var teacherobj= new Teacher("A","B",23,"Male","Love","Physics");
console.log(Object.getOwnPropertyNames(Person));
console.log(Object.getOwnPropertyNames(Teacher));
console.log(Object.getOwnPropertyNames(Person.prototype));
console.log(Object.getOwnPropertyNames(Teacher.prototype));
console.log(teacherobj)
//console.log(Teacher.prototype.constructor)
//console.log(Object.getPrototypeOf(personobj));
//console.log(Person.prototype);
var a={
id:1,
name:2
}
var b =function(i){
this.a=i;
}
//console.log(Object.getOwnPropertyNames(a));
//console.log(Object.getOwnPropertyNames(b));
var a1=Object.create(a);//Object.create with Object literal creates a prototype and stores all properties of "a" in newly created objcets prototype.
var b2=new b(99);//doesnot create a prototype.
var b1=Object.create(b,{
i:{
value:89
}
});//
console.log(a1);
console.log(b2)
console.log(b1)
//The object used in Object.create actually forms the prototype of the new object, where as in the new Function()...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.