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('提示错误消息')//注意构造函数不带参报错,因为空参构造函数级别低
慕妹3146593
TA贡献1820条经验 获得超9个赞
直接ClientAB().debug()
var ClientAB = (function(){...return ClientAB;})(); // 这其实是原始的类的声明方式
那么ClientAB就是function ClientAB(ws){...}这个方法本身啊,直接调用,prototype上有debug方法
或者像二楼那样new出来
添加回答
举报
0/150
提交
取消