JSFiddle - React, Tailwind, and code Playground
by Zaheer Ahmed
JavaScript
//Define a functional object to hold employee in JavaScript
var Employee = function(name) {
this.name = name;
};
//Add dynamically to the already defined object a new getter
Employee.prototype.getName = function() {
return this.name;
};
//Create a new object of type Employee
var judy= new Employee("Judy");
//Try the getter
alert(judy.getName());
//If now I modify employee, also Judy gets the updates
Employee.prototype.alertMyName = function() {
alert('Hello, my name is ' + this.getName());
};
//Call the new method on john
judy.alertMyName();