搜索
javascript - js中报错不是一个函数
伊谢尔伦
伊谢尔伦 2017-04-10 16:33:02
[JavaScript讨论组]

在下面的代码中:报错说hhFn()不是一个函数这是为啥呢
h5.prototype = {

    init:function(){
        this.bindEvent();
    },
    moveFn:function(diff){
        for(var i = 0;i<aLi.length;i++){
            aLi[i].className = "";
            ap[i].className = "";
        }
        if(diff<0){
            aLi.eq(index+1).className = "selected";
            ap.eq(index+1).className = "selected";
            if(index == 3){
                index = -1;
            }
        }else{
            aLi.eq(index-1).className = "selected";
            ap.eq(index-1).className = "selected";
            if(index == 0){
                index == 4;
            }
        }
    },
    touchStartFn:function(event){
        var that = this,
            touch = event.touches[0];
        startX = touch.pageX;
    },
    hhFn:function(){
        console.log("zzz");
    },
    touchMoveFn:function(event){
            touch = event.touches[0],
            x = touch.pageX,
            index = this.getAttribute("index"),
            diff = x - startX;
        this.hhFn();**为啥在这里会说hhFn()不是一个函数**
    },
   
    bindEvent:function(){
            var that = this;
            for(var i = 0;i<aLi.length;i++){
                ap[i].addEventListener('touchstart', that.touchStartFn, false);
                ap[i].addEventListener('touchmove', that.touchMoveFn, false);
            }
    }
};
new h5;`请输入代码`
伊谢尔伦
伊谢尔伦

小伙看你根骨奇佳,潜力无限,来学PHP伐。

全部回复(2)
怪我咯

闭包里面不要用this,var that = this;that.hhFn();

阿神

你那个h5不是个构造函数。。。
首先你要

function h5(){
}
h5.prototype={
}
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号