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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T06:14:22+00:00 2026-05-16T06:14:22+00:00

Later today, I was scrolling through ejhon.com slides and I found out the following:

  • 0

Later today, I was scrolling through ejhon.com slides and I found out the following:

Give this code

function katana () {
this.myvar = true;
}
katana ();
console.info (myvar);

Past the moment I compiled the code, I thought that myvar is attached to the katana function. Actually, it gets attached to the window objects, which pollutes the global namespace.

I returned to my projects, which all uses the same approach.. a little bit differently

function katana () {
this.myvar = true;
}
var xyz = new katana();
console.info (myvar);

I have a function object and instead of executing the function, I just create a new instance of it (I’m not actually quite sure what’s happening). I then use xyz to store values and use those values through prototyped methods to do some jobs.

What surprised me is when I did some debugging with FireBug is that xyz is not existent. There is no variables attached to window object. Why?

I did some more debugging and the xyz object is attached to window > object, but in the DOM it’s not apparent and has no traces. There is also something new in the debugging window, a node called ‘scopechain’ with a call and that has the values of the xyz object.

Okay, what’s happening underneath? Is that a good method that I should stick with or shall I look for an alternative?
I have looked at some questions and answers, I’m mainly looking for what this method do in the background.

  • 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-16T06:14:22+00:00Added an answer on May 16, 2026 at 6:14 am

    When you say new katana(), Javascript calls the katana function, with a new blank object as this. Once it returns, presumably initialized, the new object (or whatever katana returns, as long as it’s an object) is set up so that its ‘prototype’ (the object that it’ll inherit fields and such from) is the same as the katana function’s prototype.

    Yeah, that didn’t make much sense either the first time i went through it. The oversimplified version is, you say new katana(), and Javascript creates what’ll be a katana instance and lets the katana function initialize it. You say katana(), and this is basically the last object in the call stack to have been used in an instance method call. (If your caller was x.foo, this == x.) If there’s no such object, seems this is the same as window.

    As for why xyz isn’t showing up, you declared the variable with var. That changes the scope. If you got rid of that, you’d see a window.xyz.

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

Sidebar

Related Questions

I'm thinking about trying out MVC later today for a new app we're starting
On OS from win 2000 or later (any language) can I assume that this
My cron job is running an hour later after end of DST. This didn't
Is this functionality going to be put into a later Java version? Can someone
I need to set up two machines later today for a domo of a
The latency for a datastore put is about 150ms - http://code.google.com/status/appengine/detail/datastore/2010/03/11#ae-trust-detail-datastore-put-latency . About how
It's only started doing this today, so I assumed it was something I've done,
Still beavering away, slowly sorting out how things work. Today I've been looking at
Problem Language: C# 2.0 or later I would like to register context handlers to
What is the the best of detecting and later altering the screen resolution and

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.