JSFiddle - React, Tailwind, and code Playground

by Julian

HTML

<div id="result"></div>

JavaScript

var Promise = function() {
    this.fulfilled = no;
};

Promise.prototype.then = function(handler) {
    this._handler = handler;
};

Promise.prototype.fulfill = function(result) {
    if (this._handler) {
        this._handler(result);
    }
};

<

var fakeAjax = function() {
    var p = new Promise();

    setTimeout(function() {
        p.fulfill("my result");
    }, 1000);

    return p;
}

$(function() {
    $('#result').text("hello...");
    fakeAjax().then(function(result) {
        $('#result').text("result: " + result);
    });
});