JSFiddle - React, Tailwind, and code Playground

by JInks Peng

HTML

<div id='item'></div>

JavaScript

if(!Function.bind) {
  Function.prototype.bind = function(scope) {
    var _function = this;
    return function() {
      return _function.apply(scope,arguments);
    }
  }
}
window.onload = function() {
  var theCounter = new Counter('item',10,0);
  theCounter.counuDown();
}
function Counter(id,start,finish) {
  this.count = this.start = start;
  this.finish = finish;
  this.id = id;
  this.counuDown = function() {
    if(this.count == this.finish) {
      this.counuDown = null;
      return;
    }
    document.getElementById(this.id).innerHTML = this.count--;
    setTimeout(this.counuDown.bind(this),1000);
  }
}