Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is this pattern's name / purpose? [duplicate]

I didn't find a post asking for a pattern similar to this one, sorry if I missed it.

Anyway, I'm repeateadly seeing this pattern in many jQuery plugins or scripts:

(function () {
  ...........
}());

What's its purpose? Does it have a name?

Thanks!

like image 745
Tom Avatar asked Oct 04 '13 13:10

Tom


People also ask

Do pattern names have any cultural significance?

Some people in the sewing world are still learning that certain pattern names have an implied cultural or religious significance that the designer may not have considered. Often, designers chose the name because the pattern reflected the style of a different culture or region.

What is a number pattern?

Number Pattern is the pattern or sequence in the given series of numbers. The number pattern tells the common relationship between the given set of numbers. A repeating arrangement of numbers with a certain rule is known as a number pattern.

Why do fashion designers name their patterns?

Often, designers chose the name because the pattern reflected the style of a different culture or region. However, being unable to articulate the significance of a name can lead to a slippery slope of cultural, ethnic, and racial appropriation. Katiusca in the Rooney sweater hacked with ruffles. Katiusca in the Larkin bomber.

What are patterns in psychology?

Patterns include a series or sequence that repeats itself. The elements of a pattern repeat in a predictable manner. The patterns that we observe in our daily lives are those of colours, actions, words, letter, numbers, etc. They can be related to any event or object and can be finite or infinite.


2 Answers

It's also known as an Immediately Invoked Function Expression

Ben Alman has a good article covering IIFE usage, and why "self-executing anonymous function" isn't the best terminology:

One of the most advantageous side effects of Immediately-Invoked Function Expressions is that, because this unnamed, or anonymous, function expression is invoked immediately, without using an identifier, a closure can be used without polluting the current scope.

[... T]the term “self-executing” is somewhat misleading, because it’s not the function that’s executing itself, even though the function is being executed. Also, “anonymous” is unnecessarily specific, since an Immediately Invoked Function Expression can be either anonymous or named. And as for my preferring “invoked” over “executed,” it’s a simple matter of alliteration; I think “IIFE” looks and sounds nicer than “IEFE.”

like image 155
Michael Paulukonis Avatar answered Oct 12 '22 23:10

Michael Paulukonis


It's a an immediately invoked function expression (Fiddle):

(function () {
  alert("pee");
}());
like image 38
Joren Avatar answered Oct 12 '22 23:10

Joren