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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T20:14:37+00:00 2026-05-24T20:14:37+00:00

This is my code: var Placemat = function(id,id2) { this.hand = document.getElementById(id); this.bucket =

  • 0

This is my code:

var Placemat = function(id,id2) {
    this.hand = document.getElementById(id);
    this.bucket = "";
    this.bucketspace = document.getElementById(id2);
    this.bucketvalue = 0;
    var that = this;
    this.deal = function(id) {
        shuffle();
        var card1 = deck.shift();
        var card2 = deck.shift();
        this.hand.innerHTML = card1 + ", " + card2;
    };
    this.hit = function(id2) {
        var card3 = deck.shift();
        this.bucket = this.bucket + deck.shift();
        this.bucketspace.innerHTML = this.bucket; 
    };
};

Is this the proper way to pass parameters to a nested function? This id and id2 in this.deal() and this.hit() are from Placemat().

  • 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-24T20:14:38+00:00Added an answer on May 24, 2026 at 8:14 pm

    No, if you want to use the values that were sent to Placemat(), you need to reference them in the deal() and hit() functions. Not list them as parameters to those functions.

     // removed---------v
    this.deal = function() {
        alert( id );  // <---- do something with the original argument
        shuffle();
        var card1 = deck.shift();
        var card2 = deck.shift();
        this.hand.innerHTML = card1 + ", " + card2;
    };
    
     // removed--------v
    this.hit = function() {
        alert( id2 );  // <---- do something with the original argument
        var card3 = deck.shift();
        this.bucket = this.bucket + deck.shift();
        this.bucketspace.innerHTML = this.bucket; 
    };
    

    Remember, the parameter is just an identifier for whatever may be passed to the function. The argument is what was actually passed.

    You can reference the argument via the parameter you defined. So to have your functions reference those arguments sent to Placemat(), you can do so via the id and id2 parameters.

    But if those nested functions define their own id or id2 parameter, then that is what will be referenced in those functions. You will have effectively shadowed the parameters in the outer function.

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

Sidebar

Related Questions

Here is my code: var Placemat = function(id,id2,id3) { this.bucket = ; this.result =
I have this ajax jquery code: var form = document.getElementById('frm'); var data_string = form.serialize();
This is my code: var shuffle = function(x) { var deck = []; deck.push(x);
I have this code: var $msg = jQuery('<div></div>') .hide() .appendTo(document.body) ; if ($msg.is(:hidden)) {
Imagine I have this code: var myFunc1 = function(event) { alert(1); } var myFunc2
See this code: var MyObject = new function() { this.tos = new Array(); this.show
I have this code: var originalBorder = container.css("border"); container.hover(function(event) { event.stopPropagation(); $(this).css("border", "1px solid
I'm currently using this code: var gallery = $('ul#gallery').children(); $(gallery).filter(':even').not(':last').hover(function () {$(this).toggleClass('next')}); I'm trying
I have this code var stats = { GetMetaData : function() { var url
When I run this code: var Test = function() { return this.stuff; }; Test.stuff

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.