JSFiddle - React, Tailwind, and code Playground

by ifandelse

JavaScript

var strategies = {
    strategy1: function (a, b, c) {
        var args = arguments;
        return function (next) {
            var x = Array.prototype.slice.call(arguments, 1);
            setTimeout(function() {
                $("body").append("<div>Strategy 1</div>");
                $("body").append("<div><pre>" + JSON.stringify(args, null, 2) + "</pre></div>");
                $("body").append("<div><pre>" + JSON.stringify(x, null, 2) + "</pre></div><hr/>");
                next.apply(this, x);
            },0);
        }
    },

    strategy2: function (food) {
        var args = arguments;
        return function (next) {
            var a = Array.prototype.slice.call(arguments, 1);
            $("body").append("<div>Strategy 2</div>");
            $("body").append("<div><pre>" + JSON.stringify(args, null, 2) + "</pre></div>");
            $("body").append("<div><pre>" + JSON.stringify(a, null, 2) + "</pre></div>");
            next.apply(this, a);
        }
    },

    strategy3: function (obj) {
        var args = arguments;
        return function (next) {
            var a = Array.prototype.slice.call(arguments, 1);
            $("body").append("<div>Strategy 3</div>");
            $("body").append("<div><pre>" + JSON.stringify(args, null, 2) + "</pre></div>");
            $("body").append("<div><pre>" + JSON.stringify(a, null, 2) + "</pre></div>");
            next.apply(this, a);
        }
    }
};

var sub = {

    strategies: [],

    use: function (strat) {
        this.strategies.push(strat);
    },

    callback: function () {
        $("body").append("<div>CALLBACK EXECUTED + " + JSON.stringify(arguments, null, 2) + "</div>");
    },

    doStuff: function () {
        var idx = 0,
            self = this;
        var next = function next() {
            var args = Array.prototype.slice.call(arguments, 0);
            var thisIdx = idx;
            idx += 1;
            if (thisIdx < self.strategies.length) {
               ...