www.webdeveloper.com
Results 1 to 3 of 3

Thread: method inside method

  1. #1
    Join Date
    Jul 2004
    Location
    India
    Posts
    34

    method inside method

    function A(){
    this.B=_B;
    }

    function _B(){
    this.C=_C;
    }
    function _C(){
    alert("IN");
    }

    var a=new A();
    a.B().C();

    variable 'a' is an instance of class A().
    Trying to call method _C() as below
    a.B().C();

    which is throwing error.
    requirment is to call something like
    Menu.Options(0).Hide();

  2. #2
    Join Date
    Aug 2007
    Posts
    3,767
    Code:
    function A(){
    this.B=_B;
    }
    
    function _B(){
    this.C=_C;
    return this;
    }
    function _C(){
    alert("IN");
    }
    
    var a=new A();
    a.B().C();
    B() just calls the function, it doesn't create a new object. The return this does a similar thing to
    Code:
    new A()

  3. #3
    Join Date
    Jul 2004
    Location
    India
    Posts
    34
    Quote Originally Posted by Declan1991 View Post
    Code:
    function A(){
    this.B=_B;
    }
    
    function _B(){
    this.C=_C;
    return this;
    }
    function _C(){
    alert("IN");
    }
    
    var a=new A();
    a.B().C();
    B() just calls the function, it doesn't create a new object. The return this does a similar thing to
    Code:
    new A()


    gr8...thanks

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles