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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T22:26:55+00:00 2026-05-17T22:26:55+00:00

This is my first post. I’m trying to do some basic meta-programming with javascript,

  • 0

This is my first post.

I’m trying to do some basic meta-programming with javascript, and I was wondering if there is a way of get the id of a particular object and with that id, access to the variable name, or get simply the variable name of a particular object. I wanna recreate a situation in which you first create every single html in a web page, and append to some of the html tags events associated to a particular class -example class Person-. for example: Supposed the next code:

var someFunction = function(someText){alert(someText);}
function SomeClassFunction(){
     this.aClassFunction = someFunction;
}

var aVariableName = new SomeClassFunction();

and in the HTML code suppose I have the next piece of code.

<html>
  <head>
    <title></title>
  </head>
  <body>
    <div onclick="aVariableName.aClassFunction('Some text to show in alert');">
    </div>
  </body>
</html>

Then, as you may notice the onclick event uses the aVariableName I created before, but because I first create the name of the variable and then append the name in the code cause I knew aVariableName was the name of that object. What I wanna do or implement is to create the text above in html without know the variable name of an specific object. I have surfed on the net but, unfortunately I haven’t found anything about it.

  • 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-17T22:26:55+00:00Added an answer on May 17, 2026 at 10:26 pm

    i dont know how to get the name of a variable from the code its self without doing a whole load of work parsing stuff, which will get messy, and i’d shoot someone for this.

    var someValue;
    var foo = function() { someValue; }
    alert((foo + '')); // this is now a string, use substr to extract variable name
    

    You know you can set events like this in javascript someElement.onclick = someFunction so you dont really need to know the name of the variable if all you’re doing is setting an event handler.

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

Sidebar

Related Questions

This is my first post here and I wanted to get some input from
This is my first post on StackOverflow, so please be gentle... I have some
This is my first post on StackOverflow. This community has provided me with some
This is my first post. Please forgive me for asking a basic question as
This is my first post and I'm quite a novice on C++ and compiling
Well, this is my first post here and really enjoying the site. I have
this is first post here and I am a noob programmer. This may be
This is my first post on this rather spiffing website so go easy on
this is my first post here. I'm using an existing Flash widget but would
this is my first post.. so I'm learning Android & Java (coming from Actionscript),

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.