Last active
September 7, 2015 15:50
-
-
Save mzahor/f87333a39afdbeec2f42 to your computer and use it in GitHub Desktop.
Method overloading in js
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
var Person = function () { | |
this.name = "unnamed"; | |
}; | |
Person.prototype.getName = function () { | |
return this.name; | |
}; | |
var Student = function () { | |
this.name = "Student"; | |
}; | |
Student.prototype = new Person(); | |
Student.prototype.getName = function() { | |
// Student.prototype.constructor points to Person function | |
return "Mr " + Student.prototype.constructor.prototype.getName.call(this); | |
}; | |
var b = new Student(); | |
console.log(b.getName()); // "Mr Student" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment