Page 111 - DCAP202_Fundamentals of Web Programming
P. 111

Fundamentals of Web Programming




                    Notes
                                     Did u know?  unescape() method is used to decode the encoded strings.




                                     Notes  Use of eval method is not advised for the following reasons:

                                         security risk
                                         debugging may be difficult
                                         may result at resource hog since each invocation of eval() creates a new instance of
                                          Javascript interpreter.

                                   8.3.3 User-defined Functions

                                   An user-defined function saves us from rewriting the same code again and again and helps us to
                                   make our application smaller. The given examples will help you to understand how can you put
                                   them to work.
                                   JavaScript has so many built-in functions, besides that you can make your own as per the need.
                                   General structure of the user defined function is:
                                   function function_name(par1, par2,..){ statement}
                                   par1, par2 are the name of the parameter, one function could have one, more than one or no
                                   parameter. Parameters could be of any datatype.
                                   Example (Simple Function):
                                   <html>
                                   <head>
                                   <title>Write  your  title  here  </title>
                                   <script  type=”text/javascript”  >
                                   function  display()
                                   {
                                   document.write(“Hello  there”);
                                   }
                                   display();
                                   </script>
                                   </head>
                                   </html>
                                   Output:
                                   Hello there

                                   8.3.4 Calling Functions

                                   You can call the function from any other JavaScript. After the function is executed, the other
                                   script that called it goes on from the call.
                                   alert(‘Example  1:  the  House’);
                                   example(1,’house’);
                                   (do  more  stuff)
                                   So this script first generates an alert box, then calls the function and after the function is finished
                                   it continues to do the rest of the instructions in the calling code.



          104                               LOVELY PROFESSIONAL UNIVERSITY
   106   107   108   109   110   111   112   113   114   115   116