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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T20:07:26+00:00 2026-05-23T20:07:26+00:00

a function can return null , but is there any way for the new

  • 0

a function can return null, but is there any way for the new instance of a function to return null?

for example, in this silly code (strictly for purposes of illustration)

var f = function(j) { if( j > 5 ) return null; this.j = j; };
for( var f1=f(1); f1; f1=f(fi.j) ) {
   ...
}

what the code does not do is have new f() return null – it seems when new the return value is simply being thrown away. here new f() has not guts at all except __proto__, but refuses to nullify itself.

is the reasonable alternative to look for a gutless “object” being returned? if so, not knowing before hand what the “object” supposed to look like, what would be the best way to test for this?


solution:

considering that javascript’s new cannot fail – it must return an object and cannot return null (see answers below!), imho the proper way to accomplish the example:

var F = function(i) { if( i > 5 ) throw( 'tooMuch' ); this.i = i; }
try { 
   for( var f = new F(1); true; f = new F(f.i) ) {
      ...
   }
} catch( er ) { null; }

this uses throw/catch for loop control – has not been my cup of tea, but the new javascript specs on iterators uses this same mechanism, so I probably need to be thinking to myself “thow exceptions”, not “thow errors”.

  • 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-23T20:07:27+00:00Added an answer on May 23, 2026 at 8:07 pm

    ou CAN return your own object instead of the object given by new — but remember it has to be an object — null won’t do — although ironically typeof null is also object

    function F(x) {
      if (x < 10) return new Number(0);
    
      this.x = x;
    }
    

    now you can do your thing…

    for ( var i = 1, k = new F(i); k; k = new F(++i) ) {
      // dance .~.~.~.
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In python, you can have a function return multiple values. Here's a contrived example:
Is there a good way to find out which exceptions a procedure/function can raise
In order to return a value from a VB.NET function one can assign a
In C++, on Linux, how can I write a function to return a temporary
Is there a javascript function I can use to detect whether a specific silverlight
I have found this example on StackOverflow: var people = new List<Person> { new
gcc 4.4.4 c89 Is there a better way to do this? I have the
Sorry for constantly re-editing my question but looks like this is the only way
i often use but i have this problem. if there is a whose action
What function can I use in Excel VBA to slice an array?

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.