Skip to content

Instantly share code, notes, and snippets.

@Juszczak
Created February 6, 2020 23:11
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 Juszczak/53556b73f108998007e6ff7d4484cdcc to your computer and use it in GitHub Desktop.
Save Juszczak/53556b73f108998007e6ff7d4484cdcc to your computer and use it in GitHub Desktop.
function Person(name) {
this.name = name;
}
Person.prototype.sayHello = function() { console.log('Hello, my name is ' + this.name + '!'); }
function Student(name, id) {
Person.call(this, name);
this.id = id;
}
Student.prototype = Object.create(Person.prototype, {
sayHello: {
value: function() {
Person.prototype.sayHello.call(this, arguments);
console.log('My id is ' + this.id + '.');
}
}
});
Student.prototype.constructor = Student;
new Person(randomName())
new Student(randomName(), randomNumber(100));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment