Results 1 to 6 of 6

Thread: Can I Define and Call my Own Functions in JavaScript?

  1. #1
    Join Date
    Aug 2006
    Posts
    287

    Can I Define and Call my Own Functions in JavaScript?

    I am new to the JavaScript. Before this I have done the HTML and Core Java. I have recently started with the JavaScript. I am having doubt that whether I can define and call my own functions..?? Please help me to solve my puzzle.! Also it would be better if you provide me with the coding.! Thanks in Advance.!!
    Dimension 1100 (FMY032J) mini-tower
    2.53ghz Intel Pentium 4
    80 gig nfts HDD
    512 RAM
    Main circuit board: Dell 0CF458
    BIOS: Dell A00
    Display: Intel(R) 82865G Graphics Controller [Display adaptor]
    Multimedia: Sound MAX Integrated Digital Audio
    Windows XP Home SP2

  2. #2
    Join Date
    Mar 2008
    Posts
    672

    Re: Can I Define and Call my Own Functions in JavaScript?

    You can define your own functions, like many programming languages, in JavaScript too. Any function in JavaScript can be used to create custom object classes, simply by calling it using the keyword new. The special variable this inside the function references the new object that is being constructed, when you call it in the above way. Also you will have to keep in mind that the function should not return a value. You can define the function as a pack JavaScript statements in a block that can be used over and over again. Hope that you got some basic points from this which should be known to the JavaScript developer.

  3. #3
    Join Date
    Mar 2008
    Posts
    349

    Re: Can I Define and Call my Own Functions in JavaScript?

    Before proceeding with the coding for the defining and calling the functions that are created by you, make sure that you know about the following areas :
    • Function Name - You should always name your function so that you can call it later. For naming the function, you can use "function_name" which is the syntax.
    • Function Body - The function body is formed by the list of statements provided inside curly braces {}.
    • Parameter List - You should name parameters of the function if you want to refer to them by names.
    • Return Value - You should use "return" statements in the function body to end the execution of the function and to return a return value to the calling statement.

  4. #4
    Join Date
    Nov 2008
    Posts
    996

    Re: Can I Define and Call my Own Functions in JavaScript?

    If you want to define a new function in JavaScript, you can do that by the following way. I have provided you with the syntax format to define a new function :
    Code:
    function function_name(parameter_1, parameter_2, ...) {
       statement_1; 
       statement_2;
       ...
       return return_expression
    }
    Hope that you can understand after looking at this example.

  5. #5
    Join Date
    Jul 2006
    Posts
    289

    Re: Can I Define and Call my Own Functions in JavaScript?

    After defining your own function, you can also call it. But you will have to call it as part of an expression. Don't get confused, I have given an syntax so that you will be cleared with that :
    Code:
       ... function_name(exp1, exp2, ...) ...;
    }
    Also when you use the above syntax, the specified parameter expressions will be evaluated into primitive values or object references before passing them into the function body. Also the body of the specified function will be executed.
    Signatures reduce available bandwidth

  6. #6
    Join Date
    Aug 2006
    Posts
    235

    Re: Can I Define and Call my Own Functions in JavaScript?

    I think that you should know how to use the local variables. you would also have to know about their behave inside and outside functions. I have provided you with an example, that clarifies the above statement, :
    HTML Code:
    html>
    <head><title>Example of Local Variable</title></head>
    <body>
    <pre>
    <script type="text/javascript">
    
       scopeCheck();
    
       document.write("\n\nAfter function call:");
       
       document.write("\n   localVar is not valid");
    
       document.write("\n   localNoVar = " + localNoVar);
    
    function scopeCheck() {
       var localVar;
       localVar = "Red";
       localNoVar = "Yellow";
    
       localVar = localVar + " - Updated";
       localNoVar = localNoVar + " - Updated";
    
       document.write("\n\n Updated value in function:");
       document.write("\n   localVar = " + localVar);
       document.write("\n   localNoVar = " + localNoVar);
    }
    </script>
    </pre>
    </body>
    </html>
    3.2 (northwood)
    2gig ram
    ATI AIW X800xt 256mb
    Gigabyte GA-8knxp 875p Chipset
    Optiwrite 8X DVD Burner
    Win XP PRO Sp2 (Works Perfectly)
    2 SATA Raptor 74gig Raid 0
    2 7200 IDE 320gig HD

Similar Threads

  1. How to launch JavaScript functions in PDF
    By Abhimanyusuta in forum Software Development
    Replies: 5
    Last Post: 14-01-2010, 04:04 AM
  2. Replies: 5
    Last Post: 13-01-2010, 09:29 PM
  3. How to call a C functions within PHP?
    By Rixwel in forum Software Development
    Replies: 3
    Last Post: 05-09-2009, 09:12 AM
  4. Help With Serveral Functions in Javascript
    By twiitegxa in forum Software Development
    Replies: 0
    Last Post: 21-07-2009, 04:20 AM
  5. How to call event javascript onkeyup
    By Alexis25 in forum Software Development
    Replies: 3
    Last Post: 09-06-2009, 09:37 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,714,212,817.26018 seconds with 17 queries