сохранение функции





js/script.js
  • function fun() {
  •  document.write('Hello World!<br />');
  • }
  •  
  • //saving function in the variable
  • var val = fun();
  •  
  • //saving function in the array
  • var arra = [fun()];
  •  
  • //saving function in the object
  • var Obj = {
  •  val: fun()
  • };
  •  
  • function funMake() {
  •  val();
  •  arra[0]();
  •  Obj.val();
  • }
function fun() {
 document.write('Hello World!
'); } //saving function in the variable var val = fun(); //saving function in the array var arra = [fun()]; //saving function in the object var Obj = { val: fun() }; function funMake() { val(); arra[0](); Obj.val(); }


index.html
  • <!DOCTYPE html>
  • <html>
  • <head>
  •  <meta charset="utf-8" />
  •  <title>New Page</title>
  •  <script src="js/script.js"></script>
  • </head>
  • <body>
  • <script>
  •  funMake();
  • </script>
  • </body>
  • </html>
  • <!DOCTYPE html>
  • <html>
  • <head>
  •  <meta charset="utf-8" />
  •  <title>New Page</title>
  •  <script src="js/script.js"></script>
  • </head>
  • <body>
  • <script>
  •  funMake();
  • </script>
  • </body>
  • </html>