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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T11:28:22+00:00 2026-05-13T11:28:22+00:00

(function($) { $.fn.myFoo= function (o){ this.element = $(this) options = jQuery.extend({ name: defaultName, size:

  • 0
(function($) {

$.fn.myFoo= function (o){
    this.element = $(this)

    options = jQuery.extend({
         name: "defaultName",
         size: 5,
         global: true
      }, o);

    _min = function (){ //am i private method?
        alert('dud');
    }
    max = function (){ //am i public method?
        alert('max');
    }
    return this.o(); //o= 'max'
}
})(jQuery);

Question 1 = is there a way to call the max method/function above if i was to use this line
$('#id').myFoo('max');
Question 2 = i know that on jquery widgets an underscore “_” would mark the method as private. is this the same case on the $.fn ?

note that the line return this.o(); it is wrong its just there to demonstrate what i would like to accomplish

  • 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-13T11:28:23+00:00Added an answer on May 13, 2026 at 11:28 am

    Your code has some issues:

    First, when you run it, you will end up with three global variables, max, _min and options.

    JavaScript is function-scoped, but you should use the var statement to declare variables, if you don’t use it, and the identifier you make the assignment is not found in the scope-chain, they will become properties of the Globlal object (window).

    Second, I think you want to invoke a function passed as a String argument, if is that, you I would recommend you to use an object to group your functions, and be able to get them, if you just define your functions as variables, they are not bound to an accessible object (technically variables, arguments and function declaration identifiers are bound to the non accessible Variable Object), e.g.:

    (function ($) {
      $.fn.myFoo= function (o){
        var privateFunction = function (){ 
          alert('private');
        };
    
        var functions = {
          _min: function (){ 
            alert('_min');
          },
          max: function (){
            alert('max');
          }
        };
    
    
        functions[o](); // invoke the function
        // ...
        return this; // preserve the jQuery method "chainability"
      };
    })(jQuery);
    

    Edit: If you want to declare a “private function”, (not invokable through your String argument), you can simply declare it as a variable in the $.fn.myFoo function.

    It will be usable by all your “public functions” (all the members of the functions object) but you won’t be able to execute it using your o argument.

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

Sidebar

Related Questions

I have this jquery script : $.fn.myFoo = function(){ alert(this.selector) alert($(this).selector); } then i
function Apple(){ this.name=apple; } function Orange(){ this.name=orange; this.apple = new Apple(); this.apple.onCalled=function(){ alert(this.name); }
function Person() {} Person.prototype.population = 0; Person.prototype.constructor = function(name) { this.name = name; console.log(Name:
function killsession() { // global $_SESSION; $_SESSION = array(); if (session_id() != || isset($_COOKIE[session_name()]))
function LolClass(){ this.init = function(){ button_a.bind(tap, function(){ this.refreshFields(); // doesn't work //refreshFields(); // doesn't
function getUser() { FB.api('/me', function(response) { console.log('Response is '+response); alert('Your name is ' +
function getDbValue() { alert($('[data-bind]').length); alert($('[data-bind][0].data-bind')); alert($('[data-bind][0].value')); jQuery.each($('[data-bind]'), function(databind,key) { alert(key); alert(databind); alert(databind[key].data-bind); }) }
function stationMenu($scope){ $.ajax({ url: /users/station_names_ajax, type: POST, success: function(data){ $scope.phones = [ {name: Nexus
This is a C# console application. I have a function that does something like
function MySingletonClass(arg) { this.arr = []; if ( arguments.callee._singletonInstance ) return arguments.callee._singletonInstance; arguments.callee._singletonInstance =

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.