JSFiddle - React, Tailwind, and code Playground

by Alex Chizhov

JavaScript

function Human(name)
{
  this.name = name;
  this.oldName = name;
}

Human.prototype.renameInPassport = function(name)
{
  this.name = name;
}

Human.prototype.sayHello = function()
{
  if (this.oldName !== this.name) {
    console.log('I used to be '+this.oldName+', but now Im '+this.name);
  } else {
    console.log('Hello, my name is '+this.name);
  }
}

var humanOne = new Human('Bob');
var humanTwo = new Human('Lisa');

humanOne.sayHello();
humanTwo.sayHello();

humanOne.renameInPassport('Rob');

humanOne.sayHello();