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

  • Home
  • SEARCH
  • 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 109709
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T02:06:44+00:00 2026-05-11T02:06:44+00:00

this.String = { Get : function (val) { return function() { return val; }

  • 0
this.String = {     Get : function (val) {         return function() {             return val;         }     } }; 

What is the ‘:’ doing?

  • 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. 2026-05-11T02:06:44+00:00Added an answer on May 11, 2026 at 2:06 am

    Others have already explained what this code does. It creates an object (called this.String) that contains a single function (called Get). I’d like to explain when you could use this function.

    This function can be useful in cases where you need a higher order function (that is a function that expects another function as its argument).

    Say you have a function that does something to each element of an Array, lets call it map. You could use this function like so:

    function inc (x) {     return x + 1; } var arr = [1, 2, 3]; var newArr = arr.map(inc); 

    What the map function will do, is create a new array containing the values [2, 3, 4]. It will do this by calling the function inc with each element of the array.

    Now, if you use this method a lot, you might continuously be calling map with all sorts of arguments:

    arr.map(inc); // to increase each element arr.map(even); // to create a list of booleans (even or odd) arr.map(toString); // to create a list of strings  

    If for some reason you’d want to replace the entire array with the same string (but keeping the array of the same size), you could call it like so:

    arr.map(this.String.Get('my String')); 

    This will create a new array of the same size as arr, but just containing the string 'my String' over and over again.

    Note that in some languages, this function is predefined and called const or constant (since it will always return the same value, each time you call it, no matter what its arguments are).


    Now, if you think that this example isn’t very useful, I would agree with you. But there are cases, when programming with higher order functions, when this technique is used.

    For example, it can be useful if you have a tree you want to ‘clear’ of its values but keep the structure of the tree. You could do tree.map(this.String.Get('default value')) and get a whole new tree is created that has the exact same shape as the original, but none of its values.

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

Related Questions

Loading...

Sidebar

Ask A Question

Stats

  • Questions 57k
  • Answers 57k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer If you run script/generate scaffold without any arguments, it will… May 11, 2026 at 8:18 am
  • added an answer You are probably looking for a caching HTTP proxy, like… May 11, 2026 at 8:18 am
  • added an answer Adding an array of objects to a property grid is… May 11, 2026 at 8:18 am

Top Members

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

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

Related Questions

Loading...

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.