JSFiddle - React, Tailwind, and code Playground

by joplomacedo

HTML

<button>Click me!</button>

JavaScript

/*
The apply method lets us construct an array of arguments to use to invoke a function. It also lets us choose the value of this. The apply method takes two parameters. The first is the value that should be bound to this. The second is an array of parameters.

https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Function/apply
*/

var obj_1 = {
    prop_1: 140,
    prop_2: "what the what?"
};

var obj_2 = {
    prop_1: 30,
    meth_1: function (argol) {
        return this.prop_1 + argol;
    }
};



$('button')[0].onclick = function () {
    alert(obj_2.meth_1.apply(obj_1,[10]));
};