The difference between executing the callback function as anonymous and on behalf of

I watched one video on memory leak in JavaScript that says that a callback from a named function is better than an anonymous function in terms of memory leak. so what's the difference when I use callback both anonymous and named.

$("#abc").click(function() {
    console.log("hello")
})

and

$("#abc").click(somethingclick);

function somethingclick() {
    console.log("hello")
};
+4
source share
1 answer

This is not an answer, but a longer comment.

The video is misleading where the speaker is speaking try to avoid anonymous functions for events.

There is no difference between:

$("#abc").click(function() {
   console.log("hello")
});

and

$("#abc").click(somethingclick);
// no other code in between here
function somethingclick() {
   console.log("hello")
};

( - , ).

, , , , , , .

/ , , jQuery , .

+3

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


All Articles