0

I am working on some JavaScript code and I run into this syntax that I have never seen and I am trying hard to understand but cannot find good examples.

Can someone please describe what might be going on here?

function onMouseMove(event) {
    (function(ev) {
       // some piece of code
    })(event);
}
Brian Tompsett - 汤莱恩
  • 5,438
  • 68
  • 55
  • 126
Nikhil Das Nomula
  • 1,805
  • 5
  • 30
  • 46
  • 3
    It's an IIFE (Immediately Invoqued Function Expression). Possible duplicate of [What is the (function() { } )() construct in JavaScript?](https://stackoverflow.com/questions/8228281/what-is-the-function-construct-in-javascript) – blex Oct 23 '19 at 21:10

1 Answers1

1

This syntax is used to create an inner scope using a function and that function is immediately invoked with the event object.

Arik
  • 4,602
  • 1
  • 23
  • 23
  • Of course, we all have to ask why OP would want to do this without having other code that shows us how this makes sense to do, since the `event` argument itself should be sufficient. – StackSlave Oct 23 '19 at 21:14