JSFiddle - React, Tailwind, and code Playground

by Abdul Ahmad

JavaScript

function fruit(type) {
	var self = this;
  self.type = type;
  self.sayType = sayType;
  self.sayTypeWithDelay = sayTypeWithDelay;
  self.delays = {
  	'oneSecond': 1000,
    'fiveSeconds': 5000
  };
  
  
  function sayType() {
  	alert(self.type);
  }
  function sayTypeWithDelay(delay) {
  	setTimeout(sayType, delay);
  }
}

var f = new fruit('apple');

f.sayTypeWithDelay(f.delays.oneSecond);