0

I find the following code in an html document:

    <script type="text/javascript">
    $(function () {
    ...
    });

I cannot see any intrinsic events like onload = and would like to know how this code is called?

What is the real name and scope of this function and can I call any function defined inside? How?

skvery
  • 336
  • 2
  • 16

2 Answers2

0

Whenever you see $ before a function, or $(...).function(...) that usually denotes jQuery.

In the following fiddle I use this code, which is executed on load:

$(function () {
    alert("hi!");
});

See here: http://jsfiddle.net/VMZkW/

ryanlutgen
  • 2,951
  • 1
  • 21
  • 31
-1

It is just an anonymous function . In javascript you don't really need to give it a name and because of that after executing once you can never refer it again.

You can have anonymous functions that can be used several times, but not this one. To reuse an anonymous function you just return it to something.

And being an annonymous function it does not create any scope or naming issues and it can access everything according to where it is defined. So you can call outer function too from inside.

me_digvijay
  • 5,374
  • 9
  • 46
  • 83