2

What does this mean?

!function a(){
}({
x: [function(){alert(2);}]
})

When I reading some codes in a chrome extension, I have found this block of code. I am confused how this should work.

  • The linked duplicate explains the `!function() {}()` part. Regarding the `{ x: [function(){alert(2);}] }` part, that creates an object with a property that is an array containing one element that is a function, but then the function `a()` has an empty body so it doesn't do anything.. – nnnnnn Mar 01 '17 at 06:17

1 Answers1

2

It's just another way of writing an IIFE, using a ! operator instead of parentheses. There are a variety of operators that can be used this way:

! function(text) {
  console.log(text);
}('hello');
JLRishe
  • 99,490
  • 19
  • 131
  • 169