📜 ⬆️ ⬇️

Passing Parameters to JavaScript Event Handlers

For a very long time I couldn’t solve the problem of a simple way of passing parameters to a JavaScript event handler, but recently in the discussion of working moments with Artem Gorbunov I was struck by one idea about which

The method is simple to disgraceful, presenting for a moment that all entities in JavaScript are objects we can pass parameters as properties of a function. Illustrating by example:
function test() {
alert(arguments.callee.x);
}

test.x = 0;

window.addEventListener('load', test, false);


This example works under Firefox, but I am sure that the one who needs it will be able to implement it under any browser.

')

Source: https://habr.com/ru/post/20631/


All Articles