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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T19:33:56+00:00 2026-05-17T19:33:56+00:00

I’m pretty new to Javascript, as my SO profile will attest. I’ve just been

  • 0

I’m pretty new to Javascript, as my SO profile will attest.

I’ve just been reading up on a few tutorials and come across something I don’t totally understand in regards to Object Orientation and Encapsulation when applied with Javascript.

The tutorial stated that Javascript objects can be declared like this:

var myCustomObject = new Object();

And that you can give it instance variables like this:

myCustomObject.myVariable = "some value";
myCustomObject.myOtherVariable = "deadbeef";

Finally, it states that you can create a template function to create new objects like this:

function CustomObject(myVariable, myOtherVariable)
{
    this.myVariable = myVariable;
    this.myOtherVariable = myOtherVariable;
}

I also know that you can create and assign values to variables that do not yet exist and as a result are declared implicitly, as is seen in the example, where myCustomObject didn’t have a myVariable, but now it does.

So, my question is: What is there to prevent new variables from being added at some other point in the code. If I’m trying to learn how an object works and what I can/should do with it, I may never see the variable additions that could well be in some other .js file, and thus not have a full understanding of the object…

Also, how do I know that some object that has just been created won’t suddently turn out to have 60 more variables added later on in code that weren’t mentioned at all at creation time?

How are you meant to be able to understand what an object can contain at a glance if more can just be added to it “willy nilly”?

  • 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-17T19:33:56+00:00Added an answer on May 17, 2026 at 7:33 pm

    Javascript objects are transformers (TM), they can turn from one form to another.

    In practise this only happens to enrich objects, never to cause harm. It allows one to for example upgrade an existing ‘class’ rather then subclassing or to decorate instances again removing the need to create even more ‘classes’. Take the following example:

    var Vehicle = function(){}
    
    var factory = {
        create: function(name, props){
            var v = new Vehicle();
            v.type = name;
            for(var prop in props) {
                v[prop] = props[prop];
            }
        }
    }
    
    var bike = factory.create('Bike', {
        wheels: 2
    });
    
    var car = factory.create('Car', {
        wheels: 4,
        doors: 5,
        gear: 'automatic'
    });
    
    var plane = factory.create('Airplane', {
        wings: 2,
        engines: 4
    });
    

    Imagine what the code above would take without dynamic objects and you couldn’t do this:

    // lets paint our car
    car.color = 'candy red';
    // bling!
    car.racingStripes = true;
    car.mirrorDice = true;
    car.furryChairs = true;
    

    You get to enrich/personalize objects in a much easier way.

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

Sidebar

Related Questions

I need to clean up various Word 'smart' characters in user input, including but
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
i want to parse a xhtml file and display in UITableView. what is the
public static bool CheckLogin(string Username, string Password, bool AutoLogin) { bool LoginSuccessful; // Trim

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.