0

I am familiar with this construct in jQuery:

$('#some-element').doSomethingJQueryDoes();

But I don't understand this construct:

$(function(){
    ..
});

It appears I am passing an anonymous function to jQuery but I am curious:

  • When does this execute? From the code inside it appears to execute on document.ready
  • Is there any way to give this function a NAME so that I can call it outside of events happening, outside of its scope?

1 Answer 1

1

When does this execute? From the code inside it appears to execute on document.ready

That is correct. It has the same effect as $(document).ready(function() { /* ... */ })

Is there any way to give this function a NAME so that I can call it outside of events happening, outside of its scope?

Sure, if you want:

var myFunc = function() { /* ... */ };

$(myFunc);
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you for the concise answer

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.