Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6076099
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T10:34:09+00:00 2026-05-23T10:34:09+00:00

I’ve been dipping my toes into Javascript and now looking at the following piece

  • 0

I’ve been dipping my toes into Javascript and now looking at the following piece of code:

    var router = new(journey.Router)({  
    ...
    });

    router.root.bind(function (res) { res.send("Welcome") }); 

Question: What is the root function above bound to? What does this binding do?

I understand that ‘bind()’ is supposed to bind the execution of a function to a specified object as a context. I do not understand how a function/method can be bound to an other function. All of the references I have looked at are talking about binding to an object.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T10:34:10+00:00Added an answer on May 23, 2026 at 10:34 am

    ‘root’ is a getter method defined in journey.js (at line 145) as

    get root() {
        return this.get('/');
    },
    

    which is simply an expedient shorthand for

    get('/')
    

    And in this context, the call to bind will associate the provided callback function with the route defined as root, such that any requests that match the root path (‘/’) will be answered by the string ‘Welcome’.

    UPDATED

    Upon further examination of the journey.js source, it appears the use of bind() in this context is not an example of currying at all.

    Rather this particular bind() is defined as a function of the object returned by route() (which in turn is called by get()) in journey.js at line 131, and is simply used to set (or bind) the handler for a particular route.

    IMPORTANT: This call to bind() IS NOT the same as Function.prototype.bind().

    I’m leaving my previous answer below because I believe the information regarding currying still has value in this situation.

    This use of Function.prototype.bind() is called ‘currying’ and is used to provide a new function which has values already provided for one or more of its expected arguments.

    A simple example of currying would be if you assume:

    function addSome(amount, value) {
    return value + amount;
    }

    which could be curried to produce a new function:

    var addOne=addSome.bind(1);

    and is exactly the same as:

    function addOne(value) {
    return addSome(1,value);
    }

    Currying is a feature from [functional programming].

    See [bind – MDN Docs] for an explanation of bind() and [currying] for a formal definition of this technique.

    [functional programming]:http://en.wikipedia.org/wiki/Functional_programming
    [bind – MDN Docs]:https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Function/bind
    [currying]:http://en.wikipedia.org/wiki/Currying

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a jquery bug and I've been looking for hours now, I can't
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
link Im having trouble converting the html entites into html characters, (&# 8217;) i
this is what i have right now Drawing an RSS feed into the php,
I used javascript for loading a picture on my website depending on which small
I have a French site that I want to parse, but am running into
I want use html5's new tag to play a wav file (currently only supported
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I am currently running into a problem where an element is coming back from
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.