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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T03:29:02+00:00 2026-05-23T03:29:02+00:00

I’m trying to rewrite a Mootools tooltip class in JQuery using this class plugin

  • 0

I’m trying to rewrite a Mootools tooltip class in JQuery using this class plugin. When my class is instantiated I’m attaching an event listener to a target link which will fade out the tooltip.

In event callbacks JQuery assigns the keyword “this” to the target of the event, so to keep a reference to the properties of the class I’m using apply() to set “this” to mean the class instance. This is apparently the counterpart in JQuery of Mootools’ handy bind() function.

Unfortunately when I use apply() I lose the callback’s event parameter. For example, in this bit I get an “e is undefined” error on the second line.

this.target.bind('click', function(e){
    e.preventDefault();
    var tip = this.opts.tip;
    tip.fadeOut(500, function(){
        tip.bind('click', function(){
            showing = false;
        })
    });
}.apply(this))

Am I missing a trick here? Does anybody know a way around this 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-05-23T03:29:03+00:00Added an answer on May 23, 2026 at 3:29 am

    TBH, the mootools .bind as you call it is just Function.bind in ES5 – and is available natively in browsers that support the js 1.8.5 + spec. MooTools just enhances browsers that don’t have it yet but lets the native implementation remain on the prototype – if available.

    https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Function/bind

    You can easily implement that as a a Function.prototype.bind decorator if not available natively and use it as the example above says:

    // Function.prototype.bind polyfill
    if ( !Function.prototype.bind ) {
    
      Function.prototype.bind = function( obj ) {
        if(typeof this !== 'function') // closest thing possible to the ECMAScript 5 internal IsCallable function
          throw new TypeError('Function.prototype.bind - what is trying to be bound is not callable');
    
        var slice = [].slice,
            args = slice.call(arguments, 1), 
            self = this, 
            nop = function () {}, 
            bound = function () {
              return self.apply( this instanceof nop ? this : ( obj || {} ), 
                                  args.concat( slice.call(arguments) ) );    
            };
    
        bound.prototype = this.prototype;
    
        return bound;
      };
    }
    

    As you can see, it’s a little more involved than a simple .apply / .call

    One thing to consider is, if you NEED to use bind or if you can save a reference instead.

    eg.

    var self = this;
    this.target.bind("click", function(e) {
        var tip = self.opts.tip;
    });
    

    this has a smaller footprint than the function binding anyway. it also affords you a correct reference to this as the trigger element (event.target === this). you will find this pattern far more often in mootools-core than the bind one – though bind is often needed when you want to assign events to class methods, eg:

    this.element.addEvents({
        click: this.showTip.bind(this),
        mouseleave: this.hideTip.bind(this)
    });
    

    In this case, saving a reference won’t work though you can rewrite it as

    var self = this;
    this.element.addEvents({
        click: function(e) {
            self.showTip(e);
        }
    });
    

    A jQuery particular implementation is proxy – http://api.jquery.com/jquery.proxy/

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

Sidebar

Related Questions

No related questions found

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.