<!DOCTYPE html>
<html>
<head>
<script>
(function myFunction()
{
document.writeln("Hello World!");
})();
</script>
</head>
<body>
</body>
</html>
执行结果:
Hello World
上面js等价于:
var fn = function myFunction()
{
document.writeln("Hello World!");
};
fn();