JSFiddle - React, Tailwind, and code Playground

by rodneyrehm

CSS

body {
    height: 100%;
    background: #CCFFFF;
}

JavaScript

function log(message) {
    var p = document.createElement('p');
    p.appendChild(document.createTextNode(message));
    document.body.appendChild(p);
}

log(Function.prototype.bind
    ? "native Function.bind()" 
    : "Polyfilled Function.bind()"
);

if (!Function.prototype.bind) {

    Function.prototype.bind = function bind(that) {

        var target = this;

        if (typeof target != "function") {
            throw new TypeError();
        }

        var args = slice.call(arguments, 1),
            bound = function () {
                if (this instanceof bound) {

                    var F = function(){};
                    F.prototype = target.prototype;
                    var self = new F;

                    var result = target.apply(
                        self,
                        args.concat(slice.call(arguments))
                    );
                    if (Object(result) === result) {
                        return result;
                    }
                    return self;

                } else {

                    return target.apply(
                        that,
                        args.concat(slice.call(arguments))
                    );

                }
            };

        return bound;
    };
}

var foo = {};
var bar = {};
var handler = function() {
    log("click!");
};
document.body.addEventListener('click', handler.bind(foo).bind(bar), true)