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

The Archive Base Latest Questions

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

Is there a way to get all methods (private, privileged, or public) of a

  • 0

Is there a way to get all methods (private, privileged, or public) of a javascript object from within? Here’s the sample object:

var Test = function() { // private methods     function testOne() {}     function testTwo() {}     function testThree() {} // public methods     function getMethods() {       for (i in this) {         alert(i); // shows getMethods, but not private methods       }     }     return { getMethods : getMethods } }();  // should return ['testOne', 'testTwo', 'testThree', 'getMethods'] Test.getMethods(); 

The current issue is the code in getMethods(), the simplified example will return just the public methods, but not to private ones.

edit: my test code may (or may not) be overcomplicating what i’m hoping to get at. given the following:

function myFunction() {   var test1 = 1;   var test2 = 2;   var test3 = 3; }  

is there a way to find out what variables exist in myFunction() from within myFunction(). the pseudo-code would look like this:

function myFunction() {   var test1 = 1;   var test2 = 2;   var test3 = 3;    alert(current.properties); // would be nice to get ['test1', 'test2', 'test3'] } 
  • 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. 2026-05-10T20:49:50+00:00Added an answer on May 10, 2026 at 8:49 pm

    The technical reason why those methods are hidden is twofold.

    First, when you execute a method on the Test object, ‘this’ will be the untyped object returned at the end of the anonymous function that contains the public methods per the Module Pattern.

    Second, the methods testOne, testTwo, and testThree aren’t attached to a specific object, and exist only in the context of the anonymous function. You could attach the methods to an internal object and then expose them through a public method, but it wouldn’t be quite as clean as the original pattern and it won’t help if you’re getting this code from a third party.

    The result would look something like this:

    var Test = function() {     var private = {         testOne : function () {},         testTwo : function () {},         testThree : function () {}     };      function getMethods() {         for (i in this) {             alert(i); // shows getMethods, but not private methods         }         for (i in private) {             alert(i); // private methods         }     }     return { getMethods : getMethods } }();  // will return ['getMethods', 'testOne', 'testTwo', 'testThree'] Test.getMethods(); 

    edit:

    Unfortunately, no. The set of local variables aren’t accessible via a single, automatic keyword.

    If you remove the ‘var’ keyword they would be attached to the global context (usually the window object), but that’s the only behavior that I know of that is similar to what you’re describing. There would be a lot of other properties and methods on that object if you did that, though.

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

Sidebar

Ask A Question

Stats

  • Questions 78k
  • Answers 78k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer The file you are looking for is JBOSS_HOME/common/lib/servlet-api.jar. From the… May 11, 2026 at 3:40 pm
  • added an answer If you set GEM_HOME you can share your gem installations. May 11, 2026 at 3:40 pm
  • added an answer The W3C Markup Validator is an open source tool, which… May 11, 2026 at 3:40 pm

Related Questions

Can anyone figure out a nice way to get the following code to work?
I'd like to write a MessageConverter class that can wrap another MessageConverter. This MessageConverter
One thing I've run into a few times is a service class (like a
we have a problem to use TransactionScope. TransactionScope get to us very good flexibility

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.