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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T16:35:09+00:00 2026-06-09T16:35:09+00:00

example: function Foo() { this.bla = 1; var blabla = 10; blablabla = 100;

  • 0

example:

function Foo() {
    this.bla = 1;
    var blabla = 10;
    blablabla = 100;
    this.getBlabla = function () { 
        return blabla; // exposes blabla outside
    }
}

foo = new Foo();

original question:

I know that bla will be assigned to every instance of Foo.
What will happen with blabla?

new question:

what I understand now:

this.bla = 1;     // will become an attribute of every instance of FOO.
var blabla = 10;  // will become a local variable of Foo(**not** an attribute of every    instance of FOO), which could be accessed by any instance of FOO only if there's a method like "this.getBlabla".
blablabla = 100;  // will define a **new** (or change if exist) global(window) variable.

[Question:] Did i understand correctly?

  • 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-09T16:35:11+00:00Added an answer on June 9, 2026 at 4:35 pm

    Any internal-methods you give to this — ie: this.method = function () {}; while inside of your Foo constructor function, are all going to have a reference to the blahblah which is unique to each instance of a Foo object.

    function Wallet () {
        var balance = 0;
        this.checkBalance = function () { return balance; };
        this.depositAmount = function (amount) { balance += amount; };
    }
    
    
    var wallet = new Wallet();
    wallet.checkBalance();   // 0
    wallet.depositAmount(3);
    wallet.checkBalance();   // 3
    

    But it’s completely protected from access outside of wallet, unless you return it to somebody, from a privileged function.

    wallet.balance; // undefined;
    

    (added bit of interest — if balance is a string, a number, or a boolean, even if you return it, that won’t give people editing rights, or even permanent viewing access — scalar variables are passed by value, so you’re just passing the value of balance at the time — if, however, balance was an object, a function or an array, they’d have permanent access to modify the crap out of your internal workings)

    Note: methods HAVE to be assigned inside of the constructor for this to work.
    Prototypes can’t access internal variables.
    Adding methods later won’t give them access to internal variables.

    This means that each instance will take up a little more memory, because each has its own copy of the methods, and has its own copy of the vars.
    But if what you’re doing requires private data, this would be a good way to get it.

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

Sidebar

Related Questions

For example: > function foo() { > jQuery(whatever).each( function() { return; // this just
For example: (function() { var proxied = window.eval; window.eval = function() { return proxied.apply(this,
for example in PHP class foo{ function foo($name){ //constructor $this->name=$name; } function sayMyName(){ return
I have a loop created with each, check this example: $('.foo').each(function(i){ //do stuff });
I have such example. function Bar() { this.barVal = BarValue; } function Foo() {
Is the following example appropriate for PHP's require_once construct? function foo( $param ) {
For example : function masterMethod(this, action){ // (action); <-- But action requires $(this) to
I'm pretty new to XQuery and I'm trying to write an example function that
Example: /** * This function will determine whether or not one string starts with
If I have an example function ... function foo() { # get a list

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.