Question:

Creating JavaScript functions?

by  |  earlier

0 LIKES UnLike

I know the basics about JavaScript functions, but how do I make a function that can be used like this:

document.myFunction()

where it uses document as a variable?

 Tags:

   Report

2 ANSWERS


  1. Pal this is a special type of functions called methods .

    A method is a function that operates on an object , which is a variable of a class.

    So first , we create the class , which is just declarations of variables and methods (functions )

    Then we create an instance of  that class called an object of it .

    Then call a method on that particular object .

    Check out this

    http://www.howtocreate.co.uk/tutorials/j...


  2. <html>

    <head>

    <script>

    // extend the document object's prototype by adding

    // a new function member to its local definition - this

    // additional object will be publicly callable and only

    // available during the lifecycle of this page

    document.myFunction = function( ) {

    alert( "document.myFunction() called!" );

    }

    // call the new function, dot-referencing into the document

    // object's namespace to demonstrate that it has been added

    document.myFunction();

    </script>

    </head>

    <body>

    </body>

    </html>

Question Stats

Latest activity: earlier.
This question has 2 answers.

BECOME A GUIDE

Share your knowledge and help people by answering questions.