JSFiddle - React, Tailwind, and code Playground

by nickadeemus2002

HTML

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

JavaScript

//function toString example
function foo(){alert('x');}
var functionCode = foo.toString();
$('<p>'+functionCode+'</p>').appendTo('#result');

/*
USING CALL
*/
//global
x = 10;
//object
var o = { x: 15 };
function f(message)
{
    alert(message);
    alert(this.x);
}
//pass parameters
f("invoking f");
f.call(o, "invoking f via call");
    
var o = { x: 15 };

function f(message1, message2)
{
    alert(message1 + (this.x * this.x) + message2);
}

function g(object, func)
{           
    // arguments[0] == object
    // arguments[1] == func
    
    
    var args = []; // empty array
    // copy all other arguments we want to "pass through" 
    for(var i = 2; i < arguments.length; i++)
    {
        args.push(arguments[i]);
    }

    func.apply(object, args);
}

g(o, f, "The value of x squared = ", ". Wow!");