为了账号安全,请及时绑定邮箱和手机立即绑定

TypeError: ClientAB.ClientAB is not a function

TypeError: ClientAB.ClientAB is not a function

蝴蝶刀刀 2019-02-26 13:15:36
import React from 'react';import CoffeeScript from '../../../utils/coffeeScript01'class Basic extends React.Component {    constructor() {        super();        this.state = {            data: ''        }    }    componentDidMount(){        // 在初始 render 之后才执行        var ClientAB = (function() {            var now;            function ClientAB(ws) {                this.ws = ws;                this.ws.binaryType = "arraybuffer";                this.counter = 0;                this.connected = false;                this.heartbeat = {                    outgoing: 10000,                    incoming: 10000                };                this.maxWebSocketFrameSize = 16 * 1024;                this.subscriptions = {};                this.partialData = '';            }            ClientAB.prototype.debug = function(message) {                var _ref;                return typeof window !== "undefined" && window !== null ? (_ref = window.console) != null ? _ref.log(message) : void 0 : void 0;            };            return ClientAB;        })();        ClientAB.ClientAB('aa').debug('提示错误消息')    }    render() {        console.log('==============taskNames==============')        console.log(this.state.taskNames)        const taskNames = this.state.taskNames;        var divStyle = {        }        return (            <div id style={divStyle} className='data-line'>                {taskNames}            </div>        )    }}export default Basic;
查看完整描述

3 回答

?
慕莱坞森

TA贡献1810条经验 获得超4个赞

var clientAB = new ClientAB('aa');

clientAB.debug('提示错误消息');

//or

ClientAB('aa').debug('提示错误消息')//注意构造函数不带参报错,因为空参构造函数级别低


查看完整回答
反对 回复 2019-03-14
?
慕妹3146593

TA贡献1820条经验 获得超9个赞

直接ClientAB().debug()

var ClientAB = (function(){...return ClientAB;})(); // 这其实是原始的类的声明方式

那么ClientAB就是function ClientAB(ws){...}这个方法本身啊,直接调用,prototype上有debug方法

或者像二楼那样new出来


查看完整回答
反对 回复 2019-03-14
?
月关宝盒

TA贡献1772条经验 获得超5个赞

这样写,还不如不要使用react。多费劲呀~


查看完整回答
反对 回复 2019-03-14
  • 3 回答
  • 0 关注
  • 724 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信