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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T04:24:16+00:00 2026-05-31T04:24:16+00:00

From here : function highest(){ return makeArray(arguments).sort(function(a,b){ return b – a; }); } function

  • 0

From here:

function highest(){ 
  return makeArray(arguments).sort(function(a,b){ 
    return b - a; 
  }); 
} 

function makeArray(array){ 
  return Array().slice.call( array ); 
} 

assert(highest(1, 1, 2, 3)[0] == 3, "Get the highest value."); 
assert(highest(3, 1, 2, 3, 4, 5)[1] == 4, "Verify the results.");

Now, why does Array() even return something meaningful, without a new operator? Most “class” definitions I’ve seen in JS return undefined if called without new:

function User(name) {
  this.name = name;
  this.jump = function() {
    console.log(name + " is jumping!");
  }
}

assert(typeof(User("no New")) == 'undefined');
  • 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-31T04:24:17+00:00Added an answer on May 31, 2026 at 4:24 am

    The specification explicitly dictates this:

    When Array is called as a function rather than as a constructor, it creates and initialises a new Array object. Thus the function call Array(…) is equivalent to the object creation expression new Array(…) with the same arguments.

    How it’s done internally depends on the implementation, but for custom constructors you can use the following trick:

    if(!(this instanceof User)) return new User(name);
    

    … because new User(...) sets this to the created User instance, whereas User(...) sets it to the global object. (So you were in fact setting global variables in the last snippet.)

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

Sidebar

Related Questions

function highest(){ return makeArray(arguments).sort(function(a,b){ return b - a; }); } function makeArray(array){ return Array().slice.call(
I call a javascript function from a textbox by using OnKeyPress=clickSearchButton() Here is my
I often hear around here from test driven development people that having a function
I need to pass an url from asp.net load_page to flowplayer javascript function here:
i need a Function Pointer from a base class. Here is the code: class
Hi I've been using the array_sort() function found here for some time to sort
i'm using the code from here: http://phlymail.com/en/downloads/idna/download/ and built a function like this (from
I have a problem to get the highest Value in a dynamic List of
I'm using this function from here , which is: // highlight search keywords function
Doubt originated from here int g() { cout << In function g() << endl;

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.