www.webdeveloper.com
Results 1 to 6 of 6

Thread: Syntax Question

Hybrid View

  1. #1
    Join Date
    Nov 2013
    Posts
    4

    Syntax Question

    Hi all :-)

    I cannot find an answer to brackets followed by brackets like this:

    PHP Code:
    this._config.connectionHandler.bind(this)(socket); 
    This is used with node.js and socket.io

    In my opinion there is no way to follow () by () ... but code works.

    Maybe someone can explain, give a link or a tip to search for to learn backgrounds.

    Thanks for your time :-)

    Dan

  2. #2
    Join Date
    Jul 2003
    Location
    The City of Roses
    Posts
    2,503
    It would mean that the expression

    this._config.connectionHandler.bind(this)

    returns a function, and that returned function is then invoked by

    (socket)
    for(split(//,'))*))91:+9.*4:1A1+9,1))2*:..)))2*:31.-1)4131)1))2*:3)"'))
    {for(ord){$i+=$_&7;grep(vec($s,$i++,1)=1,1..($_>>3)-4);}}print"$s\n";

  3. #3
    Join Date
    Nov 2013
    Posts
    4
    thanks for reply :-)

    is there a different way to write this ?

    Maybe:

    PHP Code:

    function callFunction(){
       
    this._config.connectionHandler.bind();
    }
    socket.callFunc(); 

  4. #4
    Join Date
    Nov 2013
    Posts
    4
    I cannot edit my post...

    Is the reason a programmer does this, the timing of calling the function after binding ?

  5. #5
    Join Date
    Dec 2011
    Location
    Centurion, South Africa
    Posts
    795
    My guess, the reason behind the bind function passing back a function, instead of handing the entire operation itself, is because you could use the returning function multiple times afterwards.

    So you would initially do the binding, but assign the resulting function to a variable:

    Code:
    var myConnection = this._config.connectionHandler.bind(this);
    Then when you want to use it elsewhere in the program:

    Code:
    myConnection(socket);
    JavaScript: Learn | Validate | Compact | bionoid

  6. #6
    Join Date
    Nov 2013
    Posts
    4
    Now I understand - thanks interesting.

    @bionood & Jeff Mott: Thank you

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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