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

Can a function in R return not one, but two vectors? (I am really
can u please help me how to return an instance of a function which
Is there any way to use DataContext to execute some explicit SQL and return
I need a function that can return the difference between the below two dates
Does Actionscript have a built-in function that accepts a number and can return a
Can a function return more than one value directly (i.e., without returning in parameters
In order to return a value from a VB.NET function one can assign a
I have a class with an __init__ function. How can I return an integer
How can I write a function which will return pi (π) to a given
How can I build a function slice(x, n) which would return a list of

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.