0

There are person class and student class. And student wants to inherit person property using only prototype. How i can use prototype to inherit fname, lname.

function Person(fname, lname){
  this.fname = fname;
  this.lname = lname 
}

function student(sid){
  this.sid = sid;
}

var s = new student("John","joy", 12);
console.log(s.name);
Rohit
  • 2,603
  • 2
  • 21
  • 44
  • 1
    See the second part of the accepted answer to: [*What is the 'new' keyword in JavaScript?*](http://stackoverflow.com/questions/1646698/what-is-the-new-keyword-in-javascript/3658673#3658673). There are likely many, many duplicates of this question along the lines of "*How do I create a subclass?*", noting that ECMAScript doesn't have classes. There should be one that includes *Object.create()*, which is the ES5 way of doing things. – RobG Jun 12 '15 at 03:15
  • See [*Using “Object.create” instead of “new”*](http://stackoverflow.com/questions/2709612/using-object-create-instead-of-new) for the ES5 way of doing things. – RobG Jun 12 '15 at 03:20
  • "*How i can use prototype to inherit fname, lname.*" - you cannot. They're not prototype properties. – Bergi Jun 12 '15 at 06:23

0 Answers0