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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T02:39:34+00:00 2026-06-11T02:39:34+00:00

I was watching the Douglas crockford video on javascript and one the thing that

  • 0

I was watching the Douglas crockford video on javascript and one the thing that he mentioned was in case you forget to use new for class then it will populate the global namespace which in browser is window. I wanted to understand this better so I went and test this out as below

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

var user = new User("John","Resig");
alert(window.name); // expected to see undefined, but was John Resig
alert(user.name); // this should only show John Resig correctly

var user1 = User("Douglas","Crockford");
alert(window.name); // expected to see Douglas Crockford and shown correctly

There is two possibility now, either my understanding of global namespace is wrong or my example is wrong.
Appreciate if you could set me in the right direction.

  • 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-06-11T02:39:36+00:00Added an answer on June 11, 2026 at 2:39 am

    The reason is this in the User function refers to window if new isn’t used. The default this for a function (in traditional JavaScript[1]) is window.

    [1] Browsers which support 'use strict' won’t behave this way in strict mode. Instead they will throw an exception because this is undefined if new, apply, call, bind, etc. aren’t used. See http://jsfiddle.net/ufTq9/

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

Sidebar

Related Questions

I'm watching Douglas Crockfords Theory of the DOM and he mentioned that the location
So I finished watching Douglas Crockford's excellent series on Javascript, and in the final
Watching few examples that use repository pattern like StoreFront I couldn't figure out where
I'am watching some video tutorial about css and find realy strange thing. First of
I have been watching a video of a conference (See: Good JavaScript Habits for
I recently watching this video on Google Chrome with great interest. It explains that
Watching a WWDC 2011, I saw advice (but not an explanation) that one should
I've been watching a video that stated that UIAlertView works only if UIKit.h has
I've been watching Douglas Crockford's talks at YUI Theater, and I have a question
After watching the WWDC video on the accelerate framework, I saw that it had

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.