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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T20:49:47+00:00 2026-05-15T20:49:47+00:00

I’ve just discovered the way to create fake ‘classes’ in javascript, but I wonder

  • 0

I’ve just discovered the way to create fake ‘classes’ in javascript, but I wonder how you can store them and still get easy access to their functions in an IDE.

Like this:

function Map(){
   this.width = 0;
   this.height = 0;
   this.layers = new Layers();
}

Now I’ve got a function that loops through an XML and creates multiple Map() objects.
If I store them under a single variable, I can access them just fine, like:

map1 = new Map();
map1.height = 1;

But I don’t know under what name they’ll be stored!
So I thought I could save them like this:

mapArray = {};
mapArray['map1'] = new Map();

But you can’t access the functions like this: (At least the IDE code completion won’t pick it up)

mapArray['map1'].height = 1;

I then thought this would be the best solution:

function fetch(name){
    var fetch = new Map();
    fetch = test[name];
}

That way I could write:

fetch('test').height = 1;

But this seems like it’ll generate lots of overhead continuously copying variables like that.

Am I overlooking something simple?

  • 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-15T20:49:48+00:00Added an answer on May 15, 2026 at 8:49 pm

    The reason it doesn’t work is that, in order for a map/array to allow anything inside it, it must assume only that the things inside are at most a very low-level thing on the inheritance tree. Unfortunately, unlike Vector<> and proxy objects in Actionscript, and similar things in other languages, this isn’t easy to do in Javascript.

    How would you overload the [] operator in javascript

    The solution you have, if that’s what functionality you would like, is about the simplest you can do. You can also make a .get(whatever) function that returns what [whatever] is, but specifically as the type you want. And you can make a .set(whatever,value) as well. However, it won’t stop the code from shoving things in using [].

    On one hand, it’s not a good idea to depend too heavily on the IDE to do this for you, but attempting to strongly-type things better is not a bad idea in and of itself.

    Update:

    To answer your other question… First, to easily test simple JS things, it’s nice to use the command-line version:

    http://blog.thefrontside.net/javascript/learning-javascript-from-the-command-line

    https://developer.mozilla.org/en/SpiderMonkey_Build_Documentation

    Now, I’m also not recommending you do this just to hack the IDE, but just to show “a way” to do it:

    # js
    js> function FooDataClass(){ this.data = "argh!"; }
    js> function FooClass(){ this.get = GetStuff; this.put = PutStuff; this.stuff = new FooDataClass(); }
    js> function PutStuff(name,stuff){ this[name]= this.stuff = stuff; }    
    js> function GetStuff(name){ return this.stuff = this[name]; }     
    js> f = new FooClass()       
    [object Object]
    js> f.put('bar', new FooDataClass())       
    js> f.get('bar')    
    [object Object]
    js> f.get('bar').data
    argh!
    js> 
    

    This might fake out your IDE for you.

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

Sidebar

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.