TypeError: ClientAB.ClientAB is not a function

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;

https://img2.mukewang.com/5c89fbe100016e9e08000477.jpg

https://img2.mukewang.com/5c89fbe300019a0608000448.jpg


蝴蝶刀刀
浏览 725回答 3
3回答

慕莱坞森

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

慕妹3146593

直接ClientAB().debug()var ClientAB = (function(){...return ClientAB;})(); // 这其实是原始的类的声明方式那么ClientAB就是function ClientAB(ws){...}这个方法本身啊,直接调用,prototype上有debug方法或者像二楼那样new出来

月关宝盒

这样写,还不如不要使用react。多费劲呀~
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript