Skip to content

Instantly share code, notes, and snippets.

@conanak99
Last active January 16, 2019 04:14
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save conanak99/47a08f561f660734d55c to your computer and use it in GitHub Desktop.
function Person() {
this.firstName = 'Per';
this.lastName = 'son';
this.sayName = function() { return this.firstName + ' ' + this.lastName };
}
// Viết một Constructor Function khác
function SuperMan(firstName, lastName) {
this.firstName = firstName;
this.lastName = lastName;
}
// Ta muốn SuperMan sẽ kế thừa các thuộc tính của Person
// Sử dụng prototype để kế thừa
SuperMan.prototype = new Person();
// Tạo một object mới bằng Constructor Function
var sm = new SuperMan('Hoang', 'Pham');
sm.sayName(); // Hoang Pham. Hàm này kế thừa từ prototype của Person
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment