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

The Archive Base Latest Questions

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

From Secrets of the Javascript Ninja (great walkthrough btw): // We need to make

  • 0

From Secrets of the Javascript Ninja (great walkthrough btw):

// We need to make sure that the new operator is always used
function User(first, last){ 
  if ( !(this instanceof User) ) 
    return new User(first, last); 

  this.name = first + " " + last; 
} 

var name = "Resig"; 
var user = User("John", name); 

assert( user, "This was defined correctly, even if it was by mistake." ); 
assert( name == "Resig", "The right name was maintained." );

Do any real-world code style guides make all constructors do this kind of safeguarding (the first two lines)? I believe linters will catch calls like User("John", "Resig") and warn about the missing new, won’t they?

  • 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:12:54+00:00Added an answer on May 31, 2026 at 4:12 am

    I recommend you use strict mode and test in a browser that supports it. For example,

    function User(first, last) {
        "use strict";
        this.name = first + " " + last;
    }
    

    this will throw in strict mode if you neglect the new. For example,

    User("a", "b")
    

    will throw a TypeError in Firefox. This allows you to catch errors without having to pay the penalty of an instanceof check. It throws a type error even if you call it outside of strict mode. This is because directly invoked strict mode funcitons have this bound to undefined instead of global. Setting a property on undefined results in a TypeError exception.

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

Sidebar

Related Questions

I've created a simple Facebook app that doesn't need any data/info from users. When
For AJAX on my website, I make calls from a Javascript file to something.php?request=bla.
From my understanding the XMPP protocol is based on an always-on connection where you
I want to extract version number from string. a string = Tale: The Secrets
I am looking at an embedded system where secrets are stored in flash that
I am working on a c# program that retrieves information from a webservice and
I've been looking for a way to call Objective-C code from some JavaScript in
I need to generate many internal client-side (within the company only) graphs from streams
Hi I'm trying to grab all pictures from a specific album (always the same
I'm new to javascript/ajax and a bit stuck right now. The assignment is to

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.