Sub Classes

Creating Sub classed and use prototype

by manoj_antony32

JavaScript

var student = function(xyz){
		this.private='sample';
		this.xyz = xyz;
};

student.prototype.details = function(standard, percentage){
		this.standard = standard;
    this.percentage = percentage;
		return this.xyz+" studying "+this.standard+" and got "+this.percentage+" percentage";
};


var college = function(){
	student.call(this);
};

college.prototype.details = Object.create(student.prototype);
college.prototype.constructor = college;

college.prototype.details = function(yearStudying, percentage){
		this.yearStudying = yearStudying;
    this.percentage = percentage;
		return " studying "+this.yearStudying+" and got "+this.percentage+" percentage";
};


var person1 = new student('mano')
console.log(person1.details('12th','65'));
var person2 = new college()
console.log(person2.details('2nd year','70'));