Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

A simple JavaScript function which is between parenthesis [duplicate]

I have downloaded an external JavaScript file and want to create a HTML5 User Interface for it. I don't understand why the JavaScript code (see bellow) initiates his main function like that.

//JavaScript Code
(function(Raphael) {
      // some codes here
})(window.Raphael);

Why is that function between parentheses?

What does the "window.Raphael" mean?


1 Answers

This is an example of a self invoking anonymous function.

You are passing in window.Raphael into this function which is essentially "renamed" to Raphael inside the function.

like image 171
Undefined Avatar answered Apr 24 '26 09:04

Undefined



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!