javascript inheritance and instance variables
javascript
Solution
All I want is to make A and B be accessible and specific for each "instance"
The typical way of doing this is to pass parameters and assign them to properties. Then you can use `call` to reference the super class. In other words:
function Person( name, age ) {
this.name = name;
this.age = age;
}
function Student( name, age, grade ) {
Person.call( this, name, age ); // call super-class with sub-class properties
this.grade = grade;
}
Student.prototype = new Person();
Student.prototype.constructor = Student;
var roger = new Student( 'Roger', 18, 'A+' );
Problem
I'm trying to understand how inheritance works in JS. Suppose we have a class: ``` Class = function () { this.A = 'A'; this.B = 'B'; }; ``` and we are trying to extend it ``` SubClass = function () {}; SubClass.prototype = new Class(); ``` Do I understance correctly that after inheritance properties `A` and `B` are common for all instances of `SubClass`, since they belong to it's prototype? If yes, how can `Class` be extended so that `A` and `B` do not be part of prototype? UPD: note that `Class` uses `A` and `B`, so I can't declare them in SubClass. Thank you in advance!