JSFiddle - React, Tailwind, and code Playground

by Trần Ngọc Minh

JavaScript

var Person = function (name) {
    this.name = name;
};
Person.prototype.get_name = function () {
    return this.name;
};
var Student = function (name) {
    this.name = name;
};
Student.prototype = new Person();
// tạo một instance cho Student
var myStudent = new Student('Ngoc Minh');
var name = myStudent.get_name(); // get_name kế thừa từ Person
alert (name);
// định nghĩa lại get_name
Student.prototype.get_name = function () {
        return "Hi, My name is: "+ this.name;
};
// tạo một instance khác cho Student
var anotherStudent = new Student('Duong Qua');
var anothername = anotherStudent.get_name(); // Hi, My name is Duong Qua
alert (anothername);