Using Named Functions Within Self-Executing Function Blocks In Javascript: Unterschied zwischen den Versionen

Aus crazylinux.de
Zur Navigation springen Zur Suche springen
(init)
 
K (typo)
 
Zeile 1: Zeile 1:
thanks Ben for this tip.<br>
thanks Ben for this tip.<br>  


http://www.bennadel.com/blog/1988-Using-Named-Functions-Within-Self-Executing-Function-Blocks-In-Javascript.htm<br>
http://www.bennadel.com/blog/1988-Using-Named-Functions-Within-Self-Executing-Function-Blocks-In-Javascript.htm<br>  


<br>


 
<source lang="html4strict"><!DOCTYPE html>
<source lang="javascript"><!DOCTYPE html>
<html>
<html>
<head>
<head>
Zeile 35: Zeile 35:
<!-- Intentionally left blank. -->
<!-- Intentionally left blank. -->
</body>
</body>
</html></source>
</html></source>  


[[Kategorie:Tips_und_Tricks]]
[[Category:Tips_und_Tricks]] [[Category:WWW]]
[[Kategorie:WWW]]

Aktuelle Version vom 16. August 2010, 16:40 Uhr

thanks Ben for this tip.

http://www.bennadel.com/blog/1988-Using-Named-Functions-Within-Self-Executing-Function-Blocks-In-Javascript.htm


<!DOCTYPE html>
<html>
<head>
<title>Named Self-Executing Functions</title>
<script type="text/javascript">
 
// Define a variable to be accessed within the
// self-executing function block.
var counter = 0;
 
// Create a self-executing function block; however, rather
// than passing in an anonymous, headless function, let's
// pass in a named function.
(function useCounter(){
 
// Increment and log counter.
console.log( ++counter );
 
// Call *this* function again in after a short timeout.
// Since it has a name, we don't have to use the
// depracated arguments.callee property.
setTimeout( useCounter, 1000 );
 
})(); // Self-execute.
 
</script>
</head>
<body>
<!-- Intentionally left blank. -->
</body>
</html>