S
S
Sergey Pugovkin2016-09-20 16:48:33
JavaScript
Sergey Pugovkin, 2016-09-20 16:48:33

How to return an anonymous function name for an event?

I want to attach a function to an event and call it at the same time. Usually they write something like this:

var f = function () {
    if (window.location.hash) {
        scrollBy(0, -150);
    }
};
f();
window.addEventListener('hashchange', f);

Is there a way to make it a little prettier? Something like this:
window.addEventListener('hashchange', (function () {
    if (window.location.hash) {
        scrollBy(0, -150);
    }
    return 'this.имя'; //??
})());

Instead of 'this.name', what?
Those. create, execute, return yourself for an event.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
DTX, 2016-09-20
@Driver86

(function() {
    return arguments.callee;
})()()()().... ;

function namedFunc() {
    return namedFunc;
}
namedFunc()()()().... ;

var storedFunc = function() {
    return storedFunc;
};
storedFunc()()()().... ;

stackoverflow.com/questions/6959426/can-a-javascript...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question