Created
February 6, 2020 23:11
-
-
Save Juszczak/53556b73f108998007e6ff7d4484cdcc to your computer and use it in GitHub Desktop.
This file contains hidden or 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 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