Created
January 2, 2015 22:17
-
-
Save deniskyashif/e0b601f067816104747f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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