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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T09:40:03+00:00 2026-05-27T09:40:03+00:00

I want to implement data hiding in JavaScript by writing a function that returns

  • 0

I want to implement data hiding in JavaScript by writing a function that returns an object from inside a closure. Here is the incorrect code:

pokerObjects.getPokerCard = (function(f, s){
        // These are immutable, so hide them in the closure
        var face = (typeof f === 'number' ? pokerObjects.faces[f] :  f);
        var suit = (typeof s === 'number' ? pokerObjects.suits[s] :  s);

        return {
            to_s: function() { return face + " of " + suit; }
          };

      })(f,s);

What I would like to do is be able to call the function getPokerCard with two parameters and have those parameters passed to the anonymous function defined parenthetically. But, passing them as written above gives me a ReferenceError: f is not defined when I try to parse the code.

  • 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-27T09:40:04+00:00Added an answer on May 27, 2026 at 9:40 am

    Maybe I’m not understanding your question correctly, but it seems like you want to assign a function to pokerObjects.getPokerCard which would allow you to later call pokerObjects.getPokerCard(f, s) which returns the object with getFace, getSuit, and to_s.

    pokerObjects.getPokerCard = function(f, s) {
        // These are immutable, so hide them in the function.
        var face = (typeof f === 'number' ? pokerObjects.faces[f] :  f);
        var suit = (typeof s === 'number' ? pokerObjects.suits[s] :  s);
    
        return {
            getFace: function() { return face; },
            getSuit: function() { return suit; },
            to_s: function() { return face + " of " + suit; }
        };
    };
    

    This accomplishes the same thing, while still ensuring that face and suit remain hidden. They are scoped variables within the function.

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

Sidebar

Related Questions

I want to implement a function for System.Data.SQLite in C#. Implementing the SQLiteFunction interface
i want to implement for loop to fetch the data from select statement.
I want to implement a sample in java that reads a configuration from some
I want to implement a generic method to retrieve header/detail data from a database:
I want to implement a TableModel, that will enable my existing data structure to
I want to implement in Java a class for handling graph data structures. I
I am performing data changes on multiple databases, and I want to implement a
Microsoft has announce that WindowsLiveID become a OpenID provider . I want implement it
I want to implement a web page (using HTML/PHP, whatever else), that will populate
I want to implement an extention to android.net.TrafficStats to measure the data traffic per

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.