JSFiddle - React, Tailwind, and code Playground
by AndyE
HTML
<div id="test"></div>
JavaScript
var elem = document.getElementById('test'); // simple div element.
var result; // store result returned.
function test_func(){}; // function declaration.
// function expression behaves identically.
elem.onclick = test_func; // assign test_func to element's onclick.
// DIRECT CALL
test_func(); // works
test_func( true ); // works
result = test_func(); // works
result = test_func( true ); // works
// DIRECT CALL, CHANGING THE CONTEXT TO THE ELEMENT
test_func.call( elem ); // works
test_func.call( elem, true ); // works
result = test_func.call( elem ); // works
result = test_func.call( elem, true ); // works ******** (surprising)
// CALL VIA ELEMENT, USING .call() METHOD, CHANGING THE CONTEXT TO THE ELEMENT
elem.onclick.call( elem ); // works
elem.onclick.call( elem, true ); // works
result = elem.onclick.call( elem ); // works
result = elem.onclick.call( elem, true ); // works ******** ( very surprising)
// CALL VIA ELEMENT
elem.onclick(); // works
elem.onclick( true ); // works
result = elem.onclick(); // works
result = elem.onclick( true ); // Error: Object doesn't support this action