Skip to content

Instantly share code, notes, and snippets.

@deniskyashif
Created January 2, 2015 22:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save deniskyashif/e0b601f067816104747f to your computer and use it in GitHub Desktop.
Save deniskyashif/e0b601f067816104747f to your computer and use it in GitHub Desktop.
(function() {
'use strict';
Function.prototype.inherits = function(Parent) {
this.prototype = new Parent();
this.prototype.constructor = this;
};
var Person = function (name) {
this.name = name;
};
Person.prototype.sayHello = function() {
return 'Hi I am ' + this.name;
};
var Student = function(name, grade) {
Person.call(this, name);
this.grade = grade;
};
Student.inherits(Person);
var p = new Person('Roy');
var s = new Student('Moss', 5);
console.log(p.constructor === Person); //true
console.log(s.constructor === Student); //true
console.log(s instanceof Student); //true
console.log(s instanceof Person); //true
console.log(s.sayHello()); //Hi I am Moss
}());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment