/*Now we will be implementing real classes using class ad we will see it’s going to give the same results
as we are getting while implementing using the functions */
class Person{
constructor(name,age){
this.name = name
this.age = age
}
}
let p = new Person(‘Harry Potter’,15)
let p2 = new Person(‘John Doe’,30)
console.log(p.proto == Person.prototype)
console.log(typeof Person)/*Internally it is still a function, the working of it still remains the same
Here still it used the prototype, all the objects of it are inherited from the prototype */
/*Only 2 difference are that we canot call the class WITHOUT using the new keyword, also we use class and
constructor keyword(explicitly)
Another difference is we can extend the class
*/
class Student extends Person{
constructor(name,age,school){
super(name,age)//super calls the parent class constructor and passes the name,age
this.school = school
}
}
let s = new Student(‘Ron Welsely’,16,‘Hogwarts’)
console.log§
console.log(s)
console.log(Student.proto == Person)//True
console.log(Person.prototype.isPrototypeOf(s))
//Why is it true and why Student.proto == Person instead of Student.proto == Person.prototype
???