SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Zealot
    Join Date
    Dec 2010
    Posts
    167
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Reference Function Inside of Function

    How can I reference a function inside of a function using OOP.

    I am trying to do this.

    Code JavaScript:
    with_field.onkeydown = function(event){
    	associate_search.fill_list.down_key(event);
    }

    Where in another file I have this type of setup.

    Code JavaScript:
    function associate_search (){
         this.fill_list      =  fill_list;
     
         function fill_list(){
               //do stuff
     
               function down_key(event){
                      //do stuff
               }
         }
    }
     
    var associate_search	= new associate_search;

    How can I reference the down_key function?

  2. #2
    SitePoint Guru
    Join Date
    Sep 2006
    Posts
    731
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    down_key is private to fill_list. If down_key is to become an event handler, then a reference to it can be returned:
    Code:
    <script type='text/javascript'>
    
    function associate_search ()
    {
      this.fill_list =  fill_list;
     
      function fill_list()
      {
        //do stuff
        alert('fill_list called');
                      
        return function down_key(event)
        {
          alert( 'down_key called' );
        }
      }
    }
     
    var as = new associate_search;
    
    window.onkeydown = as.fill_list();
    
    </script>
    Tab-indentation is a crime against humanity.


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
  •