JSFiddle - React, Tailwind, and code Playground

by demee

JavaScript

function Button(text){
    this.text = text; 
}

Button.prototype.click = function(){
    var self = this; 
    
    Ajax.get("http://myservice.com/data", self.xhr); 
    
    self.dataTimeout = window.setTimeout(function(){
        self.text = "Still waiting...";     
    }, 50);
    
    self.text = "Waiting..."; 
};

Button.prototype.xhr = function(){
    var self = this; 
    window.clearTimeout(self.dataTimeout);
    self.text = "Recived data!";
};


var button = new Button("Get data!"); 
button.click();