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 5945157
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T16:38:32+00:00 2026-05-22T16:38:32+00:00

Erm, I tried my best to explain what my problem is, sorry for by

  • 0

Erm, I tried my best to explain what my problem is, sorry for by bad English.
In the below code:

    function createCompareFunction(propertyName){

    return function(object1, object2){
       var value1 = object1[propertyName];
       var value2 = object2[propertyName];

       if(value1 < value2){
          return -1;
       }else if(value1 > value2){
          return 1;
       }else{
          return 0;
       }

    };


}

var person = [{name: "Nicholas", age: 29}, {name: "Alex", age: 34}];
person.sort(createCompareFunction("name"));
alert(person[0].name);

as you can see in this scope:

 return function(object1, object2){
   var value1 = object1[propertyName];
   var value2 = object2[propertyName];

there’s object1 and object2 arguments
but, when i call the function, i didnt defined the arguments, but why it automatically knows that it is the object in the array.

Hope you know what i’m talking. Thanks!!

  • 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-22T16:38:33+00:00Added an answer on May 22, 2026 at 4:38 pm

    See the specification for sort. It tells you what arguments it passes when it calls the function you pass to it (which are the two items in the array that it is currently sorting).

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

Sidebar

Related Questions

I need to abstract some behavioural code and have a problem trying to reference
i have a problem with a mysql ERM which is currently driving me crazy.
Erm, that's it!...
Consider the following code snippet: list<someClass>& method(); .... list<someClass> test = method(); What will
I am comparing two strings using following code string1.Contains(string2) but i am not getting
Erm... what the title says really; I have a PHP script executed by an
Reading this question , in the first comment, @Cody Gray says: Erm, you know
Erm... i promise i searched thoroughly the web for this and couldn't find a
I have the following problem that I need to express. There are persons, workplaces
I've been trying to reduce the amount of boilerplate in my code, by using

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.