Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/spring-mvc/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
不是函数错误-JavaScript es6类结构_Javascript_Ecmascript 6 - Fatal编程技术网

不是函数错误-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
})