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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T06:37:15+00:00 2026-06-11T06:37:15+00:00

I have a few JavaScript files with some jQuery code. I am including this

  • 0

I have a few JavaScript files with some jQuery code. I am including this files to the my JavaServerPages files according to needs. I am wondering how can I create object, class or something common in JavaScript, which I can use in another JavaScript files?

I have created something similar to this:

function Util() {

    Util.getString = function() {
        var newString = "hello";
        return newString;
    }
}

It takes place in my basic JavaScript file. I have included it on my basic layout JSP file. I am using it in a jQuery function in another JavaScript file in this way:

var util = new Util(); 
Util.getString();

It works properly. But why can I not use util.getString()? util is my just created object, wright?
What is the best solution to my issue?

  • 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-11T06:37:17+00:00Added an answer on June 11, 2026 at 6:37 am

    You should use prototype of the function, check here.

    function Util() {
    }
    
    Util.prototype.getString = function() {
        var newString = "hello";
        return newString;
    };
    
    var util = new Util(); 
    util.getString();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Just wondering about this... I have several separate javascript files, that all contain code
I have a sample.xhtml file which has few lines of javascript. This javascript will
I have a few divs created dynamically in Javascript.I was wondering if it is
I'm progamming in javascript/jQuery. Say, I have an array with includes a few number
I created a some javascript/jquery code to filter an html table. The filter works
We have some JavaScript code that resizes <div/> elements (adjusts height/width/padding/margin etc.) based on
I have a simple JavaScript Array object containing a few numbers. [267, 306, 108]
I have been following the usage of JavaScript for the past few years, and
I'm trying a few different approaches to Javascript inheritance at the moment. I have
I have few basic questions on session management in GWTP. Now, we create a

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.