var immediate_one = function() { return 1; }(); console.log(immediate_one) ; //1
var immediate_one = function() { return 1; }
function myfunc() { return 1; }();
(function myfunc() { return 1; })();
(function myfunc() { return 1; }())
(function() { for(var i = 1; i <= 3; i++) { document.getElementById("button-" + i).onclick = function() { //事件处理的逻辑代码写在这里 } } }());
var next, previous, rewind; (function(){ var index = -1, data = ["eeny", "meeny", "miny", "moe"], count = data.length; next = function() { if(index < count) { index++; } return data[index]; } previous = function() { if(index >= 0) { index--; } return data[index]; } rewind = function() { index = -1; } }()); console.log(next()); //eeny console.log(previous()); //undefined console.log(next()); //eeny console.log(next()); //meeny
原文:http://www.cnblogs.com/yugege/p/5138606.html