Dollar sign before self declaring anonymous function in JavaScript?
问题 What is the difference between these two: $(function () { // do stuff }); AND (function () { // do stuff })(); 回答1: The first uses jQuery to bind a function to the document.ready event. The second declares and immediately executes a function. 回答2: $(function() {}); is a jQuery shortcut for $(document).ready(function() { /* Handler for .ready() called. */ }); While (function() {})(); is a instantly invoked function expression, or IIFE. This means that its an expression (not a statement) and it