Skip to content

Instantly share code, notes, and snippets.

@mzahor
Last active September 7, 2015 15:50
Show Gist options
  • Save mzahor/f87333a39afdbeec2f42 to your computer and use it in GitHub Desktop.
Save mzahor/f87333a39afdbeec2f42 to your computer and use it in GitHub Desktop.
Method overloading in js
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