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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T16:58:25+00:00 2026-06-18T16:58:25+00:00

Base I would like to use some variables that are set from another function

  • 0

Base

  • I would like to use some variables that are set from another function within an object
  • One function, onUpdate: waits for a call to be made from somewhere else in the application
  • Second function, onRelease: triggers after a mouse click

What I am trying to achieve

There are some DOM elements I need to use for both functions. However, a document.onload won’t work here, so I am thinking that I’ll need to store them in some sort of JavaScript object.

Restrictions

(Elements are only used in this Object and must be declared inside the Object)


note: This is a custom built app so it may seem a bit confusing, but I only need to know if this can be done in the current situation


QUESTION

Is there any way to use Javascript Objects or some sort of function that stores/gets the DOM elements so they are usable throughout an Object?

Code

var ObjB = exports.ObjB = ObjA.extend({

    /* Something to contain the DOM Elements E.g.
     UI = {
         domElement: document.querySelector('#dom')
     }, 
    */ 

    onUpdate: function() {
        if(domElement.hasClass('class')) { 
            // logic using other elements
        }
    },

    onRelease: function() {
        if(domElement.hasClass('class')) { 
            // logic using other elements  
        }
    }

});
  • 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-18T16:58:26+00:00Added an answer on June 18, 2026 at 4:58 pm

    If you would like to use the dom element more then once, and you would like to avoid to call the selector everytime you want to use the element you could do it this way, but be award that this will only work if you dont remove or add the required elements later (after you called this.setupUi() the first time), because UI will only be initialized once:

    var ObjB = exports.ObjB = ObjA.extend({
    
        onUpdate: function() {
            this.setupUi();
    
            if(this.UI.domElement.hasClass('class')) { 
                // logic using other elements
            }
        },
    
        onRelease: function() {
    
            this.setupUi();
    
            if(this.UI.domElement.hasClass('class')) { 
                // logic using other elements  
            }
        },
    
        setupUi : function() {
            if( !this.UI ) {
               this.UI = {};
               this.UI.domElement =  document.querySelector('#dom');
               //add all other elements that are required by the object
            }
    
        }
    
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to base one component's x and y cooridnates according to another,
I would like some feedback on my first Python script that makes use of
I have a some JPA entities that inherit from one another and uses discriminator
I would like to write an if statement that will do something base on
I am developing an Eclipse Java project and would like to use variables to
I would like to use a generic class and force one of it's parameters
We would like to use some of our existing Java AWT graphics code on
I would like to write an abstract base class class func_double_double_t : public unary_function<double,
I would like to create a method in a base generic class to return
I would like to provide the same content inside 2 different base files. So,

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.