Jump to content
Search Community

how to pass a JS custom class method to Jquery.click()

st3f test
Moderator Tag

Warning: Please note

This thread was started before GSAP 3 was released. Some information, especially the syntax, may be out of date for GSAP 3. Please see the GSAP 3 migration guide and release notes for more information about how to update the code to GSAP 3's syntax. 

Recommended Posts

Sorry Guys, I perfectly this is not the right place for that, but I'm sure it's full of Jquery wizards here... and I'm clearly missing something.

I don't know (nor found out somewhere, sorry) how to refer to a JS class method from inside this &%/()@, damned jquery.click... (Arrrrgghhhh)

 

Thank you forever thank you

 

 

class Anthony extends Paul {
  constructor(data){
    super(data);
    // sets a reference in Pippo
    this.data.refObj = this;
    // ref to div
    this.myDiv = this.data.myDiv;

    this.content = this.data.content;
    this.btnlabel = this.data.btnlabel;

    var p = $('<div>'+ this.content +'</div>');
    p.css({'...'});

    var bt = $('<div>'+ this.btnlabel +'</div>');
    bt.css({
      '...'
    })

    /*
    bt.click(function() {
      And here, Gentlemen, I'd like very much to call...
      ...showMe() ! (Somehow)
    });
    */

    this.myHtml = p;
    this.myHtml.append(bt);

    this.myFadeTime = 0.6;
    this.showMe();
  }

}

Anthony.prototype.showMe = function(){
  	// update data in Array
  	//...
  	$(this.myDiv).css('opacity','0');
	$(this.myDiv).html(this.myHtml);
  	TweenMax.to(this.myDiv, this.myFadeTime, {opacity:'1'});
}

 

Link to comment
Share on other sites

Well, you really don't need to use the prototype like that when using classes, and when using classes, it's important to understand how to use arrow functions.

 

class Anthony extends Paul {
  constructor(data){
    super(data);
    // sets a reference in Pippo
    this.data.refObj = this;
    // ref to div
    this.myDiv = this.data.myDiv;

    this.content = this.data.content;
    this.btnlabel = this.data.btnlabel;

    var p = $('<div>'+ this.content +'</div>');
    p.css({'...'});

    var bt = $('<div>'+ this.btnlabel +'</div>');
    bt.css({
      '...'
    })

    
    bt.click(() => {
      //And here, Gentlemen, I'd like very much to call...
      this.showMe()
    });
    

    this.myHtml = p;
    this.myHtml.append(bt);

    this.myFadeTime = 0.6;
    this.showMe();
  }

  showMe() {
    // update data in Array
  	//...
  	$(this.myDiv).css('opacity','0');
	$(this.myDiv).html(this.myHtml);
  	TweenMax.to(this.myDiv, this.myFadeTime, {opacity:'1'});
  }
}

 

  • Like 4
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...