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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T00:34:53+00:00 2026-05-27T00:34:53+00:00

function Activity() { this.LoadFile = function (path, targetElement) { $.ajax({ url: path, dataType: ‘html’,

  • 0
function Activity() {

this.LoadFile = function (path, targetElement) {

    $.ajax({
        url: path,
        dataType: 'html',
        success: function (data) {
            targetElement.html(data);
        }

    });
};

this.LoadFile = function (path, targetElement, onSuccess) {

    $.ajax({
        url: path,
        dataType: 'html',
        success: function (data) {
            targetElement.html(data);
            onSuccess(data);
        }

    });
};

}

If i try to pass 2 arguments, i get onSuccess is not a function so i suppose this isnt working. Is it possible to use overloads in javascipt?

  • 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-27T00:34:53+00:00Added an answer on May 27, 2026 at 12:34 am

    There’s no way of directly specifying overloaded methods as such in JS.

    There are many workarounds.

    In your case, you can define the function with 3 parameters:

    function (path, targetElement, onSuccess)
    

    and if the function is called with only 2 parameters, onSuccess will be undefined:

    function (data) {
      targetElement.html(data);
      if (onSuccess) {
        onSuccess(data);
      }
    }
    

    You may want to look at jQuery.Callbacks for handling event callbacks, although your function could be rewritten using .load.


    For programmers coming from the Java/C# world of overloading learn the JavaScript way you can use a structure like this (not recommended, it’s simply an example for familiarity):

    function foo() {
      var fns = {};
      fns[0] = function () {
        //no params
      };
      fns[1] = function () {
        //1 param
      };
      fns[2] = function () {
        //2 params
      };
      fns[arguments.length]();
    }
    

    to provide separate functions for each “overload”, however it’s not very flexible and symptomatic of a poorly planned function.


    Oftentimes rather than using a large set of parameters, a single options parameter will be used to contain the available parameters:

    function foo(options) {
      var settings = $.extend({}, foo.defaultSettings, options);
      //do stuff with settings
    }
    foo.defaultSettings = {
      bar: 'baz',
      fizz: 'buzz'
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

<html> <script language=javascript> /* This function is invoked by the activity */ function wave()
I add html to a page using JQuery's html() function. This works great on
$(#add_activity).click(function () { $('#activities').append('@Html.Raw(Html.Partial(MyPartial).ToHtmlString())'); }); I have this bit of code that seems to
I have this little function here: public Activity getRootActivity() { Activity a = this;
function Obj1(param) { this.test1 = param || 1; } function Obj2(param, par) { this.test2
I have a little function that shows latest activity, it grab timestamp in unix
say for example I have this code in my activity: public void onCreate(Bundle savedInstanceState)
Hi to all. I have this problem, I created an activity (this activity is
I am having trouble passing data from one activity to another. I can easily
this is a rough idea of what my program looks like MainTabHost Activity (startup)

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.