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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T00:49:41+00:00 2026-06-16T00:49:41+00:00

I have been looking into the possibility of reflection in JavaScript. I already have

  • 0

I have been looking into the possibility of reflection in JavaScript. I already have a simple reflector which can list the members of an object/function, like so:

window["Foo"] = {
    "Bar": {
        "Test": function () {
            this.x = 32;
            this._hello = "Hello World";
            this._item = 123.345;

            this.hello = function() {
                alert("hello");
            };

            this.goodbye = function() {
                alert("goodbye");
            }
        }
    }
}

$(document).ready(function () {
    var x = new Foo.Bar.Test();
    Reflect(new Foo.Bar.Test());
});

function Reflect(obj) {
    for (var item in obj) {
        $("body").append(item + "(" + typeof obj[item] + ") = " + obj[item] + "<br />");
    }
}

Results:

x(number) = 32

_hello(string) = Hello World

_item(number) = 123.345

hello(function) = function () { alert(“hello”); }

goodbye(function) = function () { alert(“goodbye”); }

The next part of my challenge is to build something which can reflect back (if possible) an objects name, and the path to the object.

using this example:…

var x = new Foo.Bar.Test();

How can I reflect back “Test”, from x? For example:

ReflectName(x); //returns "Test";

Also how can I reflect back the path to x? For example:

ReflectPath(x) //returns Foo.Bar.Test

Is is possible to do these two things using JavaScript? I have researched this, and so far have not managed to come up with any viable solutions.

I do not want a solution that requires hard coding the name and path of the object/function, as this would defeat the point of using reflection.

  • 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-16T00:49:43+00:00Added an answer on June 16, 2026 at 12:49 am

    There are no classes in JavaScript (although due to code style which for reasons unknown to me imitates Java you could think there are some). Foo.Bar.Test does not mean class Test registered in namespace Foo.Bar, but function which is assigned as attribute Test of some object which is assigned as attribute Bar of some object known as Foo.

    You can’t do reflection like “give me all variables to which number 7 is assigned”, consequently you can’t list all the objects which hold Test in one of their attributes.

    This is actually good and opens new possibilities, but might be confusing in the beginning.

    BTW Since there are no classes in JavaScript, I believe term reflection is not very fortunate. And new Foo() does not mean “create new instance of Foo”, but “create a new object and execute function Foo in context of that object, and finally return it. Yeah, the new keyword is very confusing, if you want to do anything more advanced in JavaScript, never trust your Java/C# experience. JavaScript fakes Java (I suppose to not scare newcomers and allow them to do easy things quickly), but it’s very different.

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

Sidebar

Related Questions

I have been looking into backbone.js and I can't seem to figure out how
I have been looking into the possibility of creating a soft copy(image/EMF file) of
I have been looking into this for a while and can't figure it out.
I have been looking into design patterns in Javascript and found http://tcorral.github.com/Design-Patterns-in-Javascript/Template/withoutHook/index.html to be
I have been looking into Adjacency List and Nested Set Model to find the
I have been looking into recursion and TCO. It seems that TCO can make
I have been looking into this problem for a while now but I can't
I have an interesting problem which I've been looking into and would appreciate some
I have been looking into this for some hours now and can't figure it
I have been looking into javascript wysiwyg text editors for use on a topicality

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.