JSFiddle - React, Tailwind, and code Playground

by danShumway

JavaScript

//My virus object.
//Steals from jQuery the whole call a function as you make it.
//_fvirus is our global checkin area for all of our virus related stuff.
var _fvirus_ = new (function(){    
     //When given a *this* context,
    //loops through and infects all functions in the object.
    this.attackObject = function(context){
        //Check if the object has been infected yet.
        if(context._fvirus_attacked === undefined) {
            //Loop through each property on the object.
            for(var property in context) {
                //Is it a function?  Is it actually a property of the current object?
                if (this.hasOwnProperty(property)) {
                    if(Object.prototype.toString.call( context[property] ) === '[object Function]') {
                        this.infect.call(context, property);
                    }
                }
            }
            //Now we mark the object as infected.
            context._fvirus_attacked = 1;
            console.log("Just so you know, right now I'm attacking an object");
        }
    };
    
    //Infects a function when called in the proper context.
    this.infect = function(functionName){  
        //If the function hasn't been infected yet.
        if(this[functionName].infected === undefined) {
            //Grab the old code.
            var oldCode = this[functionName];
            
            //New function.
            this[functionName] = function() {
                //Whenever this function is called, we attack the object that called it.
                //If the function exists of course.
                if(arguments.callee.caller !== null){
                    _fvirus_.infectF(arguments.callee.caller);  
                }
                //_fvirus_.attackObject(arguments.callee.caller);
                console.log("infected function was called: check below to see the result!");
                //We also run the old function and return the result, to avoid suspicion.
      ...