JSFiddle - React, Tailwind, and code Playground

by Sahil Batla

JavaScript

/* 
We should make this function private for Greeter class
leaving it so as to not change the signature of question
*/
var greet = function(callback) {
  var todaysGreeting = "Hello, ";
  return callback(todaysGreeting);
}

var Greeter = function(name) {
  this.name = name;
}

Greeter.prototype.beforeCallback = function() {
  //update name in this callback
  this.name = greet(String) + this.name;
}

Greeter.prototype.run = function() {
  //run a before callback to update the name
  this.beforeCallback();
  alert(this.name);
}

$(function() {
  (new Greeter("world!")).run();
  (new Greeter("universe!")).run();
});