Skip to content

Instantly share code, notes, and snippets.

@fmtarif
Last active August 29, 2015 14:11
Show Gist options
  • Select an option

  • Save fmtarif/b8a1e8cd1824ef63bf26 to your computer and use it in GitHub Desktop.

Select an option

Save fmtarif/b8a1e8cd1824ef63bf26 to your computer and use it in GitHub Desktop.
#js self executing anonymous function explained
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<script>
/*
function test_alert(foo) {
alert(foo);
}
// test_alert('bar'); //usual
(test_alert)('bar'); //Since functions in Javascript are objects like any other,
//we can use operators on the object such as the ( and ) grouping operators.
*/
(function(foo){
alert(foo);
})('bar');
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment