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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T08:12:18+00:00 2026-06-01T08:12:18+00:00

i’ve a jquery (UI) App here where the whole JQuery Code gets a little

  • 0

i’ve a jquery (UI) App here where the whole JQuery Code gets a little bit messy, so i started to think around how to structure this in a little bit fancier way… i read a blog post somewhere, that “oop” – in a java way can be achieved by doing some kind of this:

function RangeSelector(product_id) {
    this.product_id = product_id;
    this.start_point = "#from_" + product_id;
    this.end_point = "#to_" + product_id;
}
RangeSelector.prototype.myFunction = function() { }

the whole code can be found here.

My Range Selector “Class” should hold two jquery ui datetimepickers that are responsible to let the user select a date time range for a shop where you can rent products

The problem that i currently have is the following: the date time pickers get callback functions (“unavailableFrom”, “unavailableTo”) where i’d like to do some specific things and then call a generic “unavailable” to function.
The error message is:

TypeError: 'undefined' is not a function (evaluating 'this.unavailable(date)')

I looked about that with firebug and it seems, that “this” not my object of the RangeSelector, but the HTML Element on what the datetimepicker is working.
My Question is: how can i access this method “unavailable”?

By the way, i tell you the whole story in here, because i don’t think, that the structure that i chose here is the right way to go. How do you handle these kind of things, where you have more than one html elements that have a common meaning and you would like to aggregate them?

  • 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-01T08:12:19+00:00Added an answer on June 1, 2026 at 8:12 am

    If you need to set this to a different value, you can use jQuery.proxy to do that. (Or in an ES5-enabled environment, you can use the new Function#bind function.) proxy accepts a function and value to use for this, and returns a function that will call the original with this set to that value.

    So for instance, suppose you have your RangeSelector and you want click to trigger myFunction on a specific instance:

    var r = new RangeSelector(/* ...args...*/);
    $("some_selector").click($.proxy(r.myFunction, r));
    

    Now, when r.myFunction is called, within the call, this will be a reference to the r object. (If you need to know which DOM element was clicked, have myFunction accept the event argument that jQuery passes it, and use event.target.)

    For completeness, the above using Function#bind (if the browser supports ES5 features, or you’ve included an ES5 shim [since Function#bind is shim-able]):

    var r = new RangeSelector(/* ...args...*/);
    $("some_selector").click(r.myFunction.bind(r));
    

    More to explore (on my blog):

    • Mythical methods
    • You must remember this

    The jQuery UI datepicker‘s onSelect is a bit of a pain, because they don’t give you the event object and so you don’t have access to event.target. Your best bet there is probably a closure that passes the element on:

    var r = new RangeSelector(/* ...args...*/);
    $("some_selector")..datepicker({
        onSelect: function(dateText, inst) {
            return r.myFunction(dateText, inst, this);
        }
    });
    

    …where myFunction accepts dateText, inst, and element arguments.

    Live example | source

    That works because the function we’re assigning to onSelect is a closure over the environment containing the r variable.

    Closures are frequently misunderstood; FWIW, another blog entry: Closures are not complicated

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I am reading a book about Javascript and jQuery and using one of the
this is what i have right now Drawing an RSS feed into the php,
We're building an app, our first using Rails 3, and we're having to build

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.