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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T19:22:03+00:00 2026-06-17T19:22:03+00:00

I pass an object literal into a framework method called supportP() . This object

  • 0

I pass an object literal into a framework method called supportP(). This object literal has a special property called _p which denotes that the members of it are private. From with in the object literal it can be accessed via this._p. However when I pass the object literal into the “outer” scope I do not copy _p. It has now been made private by omission. In order to access _p from public member methods I bind them to the original object using bind() so they still have access to _p via this.

Will this work? Are there other things to consider? Wanted some feedback before I tested it out.

Below are relevant snippets.

/*$A.supportP
**
**
**
*/
$A.supportP = function (o, not_singleton) {
    var oo
        key;
    SupportList[o.Name] = {};
    if (not_singleton) {
        // ignore this section
    } else { // *look here - isFunc returns true if a function
        for (key in o) {
            if ((key !== '_p') && (isFunc(o[key])) {
                oo[key] = o[key].bind(o);
            } else if (key !== '_p') {
                oo[key] = o[key];
            } else {
                // private (_p) - anything to do here?
            }
        }
        return oo;
    }
};


/*$A.test
**
**
**
*/
var singleton_object = $A.supportP({
    _p: 'I am private',
    Name: 'test',
    publik_func: function () {
        // this will refer to this object so that it can access _p
        // this._p is accessible here due to binding
    }
}, false);
  • 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-17T19:22:04+00:00Added an answer on June 17, 2026 at 7:22 pm

    Will this work?

    Yes, you will be able to access the “private” property via this._p.

    Are there other things to consider?

    You are cloning the object. Yet, the method on it has no access to it – it is bound to the “old” object whose properties will not reflect the changes on the copy. I am not sure whether this is by design or by accident.


    For strict privateness, you will need to use closures with local variables. Properties can never be made private.

    var singleton_object = (function() {
        var _p = 'I am private'; // local variable
        return {
            Name: 'test',
            publik_func: function () {
                // this will refer to this object so that it can access the properties
                // _p is accessible here due to closure, but not to anything else
            }
        };
    }()); // immediately-executed function expression
    

    Another solution, using two distinct objects (one hidden) which are passed into a framework method:

    function bindPrivates(private, obj) {
        for (var key in obj)
            if (typeof obj[key] == "function")
                obj[key] = obj[key].bind(obj, private);
        return obj;
    }
    
    var singleton_object = bindPrivates({
        p: 'I am private'
    }, {
        Name: 'test',
        publik_func: function (_) {
            // this will refer to this object so that it can access "public" properties
            // _.p, a "private property" is accessible here due to binding the private 
            //  object to the first argument
        }
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In this piece of code i pass a name into a method that modifies
I've tried to create a web method which has parameter of java.lang.Object but I
I have an object with a method that I’d like to pass to a
I pass an object literal to a function like this: pre( {model:'MUserTry'} ); I
In short, I want to use an object literal to allow me to pass
I'm struggling with something that I am sure has a very simple method, but
I want to be able to pass either a string literal, 'this is a
I hava a java application that uses Buffers to pass object around between threads.
I am trying to pass a key-value array. I am using an object literal
So I am attempting to pass object values from a bean into a primefaces

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.