不是函数错误-JavaScript es6类结构
有问题-不是函数错误,我的代码是:不是函数错误-JavaScript es6类结构,javascript,ecmascript-6,Javascript,Ecmascript 6,有问题-不是函数错误,我的代码是: import $ from 'jquery'; import gsap from 'greensock'; class IntroAnimations{ constructor(){ this.ctaEnter = $('#cta-enter'); this.loadContent = $('.center-h-v'); this.tlLoading = new TimelineLite();
import $ from 'jquery';
import gsap from 'greensock';
class IntroAnimations{
constructor(){
this.ctaEnter = $('#cta-enter');
this.loadContent = $('.center-h-v');
this.tlLoading = new TimelineLite();
this.animationTime = .5;
this.ctaEnter.click(function(){
this.removeLoadContent(); //<- error is here
})
}
removeLoadContent(){
TweenLite.to(this.loadContent, this.animationTime, {autoAlpha: 0})
}
}
export default IntroAnimations;
import$from'jquery';
从“greensock”进口gsap;
课堂介绍动画{
构造函数(){
this.cta enter=$(“#cta enter”);
this.loadContent=$('.center-h-v');
this.tlLoading=新的TimeLineite();
这个.animationTime=.5;
this.ctenter.click(函数(){
this.removeLoadContent();//这是因为“this”具有不同的上下文
使用胖箭头编写函数,它应该可以工作
removeLoadContent = ()=>{
TweenLite.to(this.loadContent, this.animationTime, {autoAlpha: 0})
}
this.ctainer.单击(()=>{
this.removeLoadContent();//这起作用了,但是如何以及为什么?@harp您可能应该阅读更多关于javascripts上下文的内容。。。
this.ctaEnter.click(() => {
this.removeLoadContent(); //<- error was here
})