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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T09:27:45+00:00 2026-06-17T09:27:45+00:00

so I’m working on recreating the card game Dominion in Javascript. I’m using OO

  • 0

so I’m working on recreating the card game Dominion in Javascript. I’m using OO Javascript, creating a card object for each card.

Rather than posting all my code here I’ll save some space and link you to it:

Site:
http://people.rit.edu/lxl1500/Prog4/Project%201/project1.html

Script:
http://people.rit.edu/lxl1500/Prog4/Project%201/main-script.js

Where I’m running into issues:

In my createActions() function I’m adding an onclick event to each image (I’m creating the images by grabbing the smallImage property of each object). This onclick should call my fullImage() function. This function will simply show a larger version of the card so the player can see the details. Therefore, I want to pass the image property, which holds the string for the source of the larger image to the function.

fullImage() will accept the object property as imageSrc. You’ll see now by clicking on an image you’ll get an alert of undefined. The only thing I can think of is when I’m calling fullImage(this.image) – this is reference to the image itself rather than the object…I’m not sure how to accomplish what I’m trying to do though. Any help would be greatly appreciated!

Thank you for your time.

  • 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-17T09:27:45+00:00Added an answer on June 17, 2026 at 9:27 am

    You’re setting onclick as an attribute. You might be able to work with that somehow, but it’s a much more elegant solution to attach an event listener:

    card.addEventListener('click', function() {
        // Handle click.
    }, false);
    

    Then you can use actionCards[i] as normal… except you can’t, because i will be one over the last index, for reasons I won’t get into here.1 The easiest way to fix that is to bind the function before you add it as an event listener:

    card.addEventListener('click', function() {
        // Handle click.
    }.bind(actionCards[i]), false);
    

    (I should note that bind is not built-in in some older browsers. While I’m on the topic of browser compatibility, addEventListener isn’t supported by old versions of Internet Explorer, either.) Then you can use this to refer to your Card object.


    Footnotes

    1 Okay, fine. It’s because of JavaScript’s function scope and that when the user has clicked it, the loop has finished, and when the loop has finished, i will be one over the number of cards.

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

Sidebar

Related Questions

Let's say I'm outputting a post title and in our database, it's Hello Y’all
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I am using JSon response to parse title,date content and thumbnail images and place
I used javascript for loading a picture on my website depending on which small
I have a small JavaScript validation script that validates inputs based on Regex. I
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I am using the SimpleRSS gem to parse a WordPress RSS feed. The only

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.