-
-
Save conanak99/47a08f561f660734d55c to your computer and use it in GitHub Desktop.
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
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