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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T20:35:15+00:00 2026-06-10T20:35:15+00:00

This is a follow-up to my previous query . I have been trying some

  • 0

This is a follow-up to my previous query. I have been trying some code since then :

var myFunc = function(){
    this.int1=1;
    var int2=2;
};
myFunc.int1=3;
myFunc.int3=4;

for(var name in myFunc){
    console.log('myFunc...'+name+'='+myFunc[name]);
};

var myFuncImpl = new myFunc();
myFuncImpl.int1=5;
for(var name in myFuncImpl){
    console.log('myFuncImpl...'+name+'='+myFuncImpl[name]);
};

And I get output as :

myFunc...int1=3
myFunc...int3=4
myFuncImpl...int1=5

I can’t answer the following questions :

  1. Why isn’t int2 visible as a property to myFunc ? It’s still in myFunc’s scope, right ? Where does this definition disappear ?

  2. Why I am I able to over-write int1‘s value outside function scope ? What if someone accidentally deletes my values outside code ? For “objects”, I understand “Object.freeze()” can help over myFuncImpl – but what about function definitions like myFunc ?

  3. Why can’t I access int3 from myFuncImpl ? Where did the prior definition (while defining myFunc) go ?

I guess my doubts are due to my thinking of myFunc as a “class” (as in Java) and myFuncImpl as an object. Perhaps I am straying too far ?

Thanks !

  • 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-10T20:35:16+00:00Added an answer on June 10, 2026 at 8:35 pm
    1. int2 is effectively a private variable, so code outside the function cannot detect it http://javascript.crockford.com/private.html

    2. This is just a fact of life with “vanilla” JS. if you need to prevent overwriting values, implement with Object.defineProperty. Caveats with IE<9

    3. int3 is a ‘static’ property to the function. It is not available on the instance, sort of like in C# if you have a static method, it’s not available to instances of the class. The difference here is you can later on in your code say myFunc.int1 = "asdf"; and now your ‘static’ property has changed. Don’t confuse static with constant
      http://elegantcode.com/2011/01/19/basic-javascript-part-7-static-properties-and-methods/

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

Sidebar

Related Questions

This is a follow up from my previous question I have this code basically
This is a follow-up questions on a previous one . Consider this code, which
This a follow-up to a previous question . How can I optimize this query
This is a follow up question to my previous question . I am trying
This is a follow-up to this previous question: Complicated COUNT query in MySQL .
This is a follow-up to my previous question: Optimisation of an oracle query I
This is a follow-up to my previous question . Suppose I am writing the
This is a follow-up to my previous question I would like to find a
This is a follow-on from a previous SO question Anchoring CSS Repeating Background Image
This is a follow up question to a previous question I asked about calculating

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.