代码示例:(标识:eg_js_function_expression_self_invoking)
<!DOCTYPE html>
<html>
<body>

<h1>JavaScript 函数</h1>

<p>可以在不调用的情况下自动调用函数:</p>

<p id="demo"></p>

<script>
(function () {
  document.getElementById("demo").innerHTML = "Hello! I called myself";
})();
</script>

</body>
</html>
运行结果: