angularjs – Typescript:TS2496:ES3和ES5中的箭头函数不能引
发布时间:2020-12-17 10:17:06 所属栏目:安全 来源:网络整理
导读:我按照一些教程如 http://www.html5rocks.com/en/tutorials/frameworks/angular-websockets/在我的node.js服务器和angular.js客户端实现socket.io,一切正常. 但是,客户端,Typescript显示以下编译错误: TS2496: The 'arguments' object cannot be referenced
我按照一些教程如
http://www.html5rocks.com/en/tutorials/frameworks/angular-websockets/在我的node.js服务器和angular.js客户端实现socket.io,一切正常.
但是,客户端,Typescript显示以下编译错误: TS2496: The 'arguments' object cannot be referenced in an arrow function in ES3 and ES5. Consider using a standard function expression. 关于以下服务代码: on(eventName:string,callback) { this.socket.on(eventName,() => { var args = arguments; // <-- here the compilation error this.$rootScope.$apply(() => { callback.apply(this.socket,args); }); }); } emit(eventName:string,data,callback?) { this.socket.emit(eventName,() => { var args = arguments; // <-- here the compilation error this.$rootScope.$apply(() => { if (callback) { callback.apply(this.socket,args); } }); }); } 我尝试了不同的解决方案,比如https://github.com/Microsoft/TypeScript/issues/1609的第一篇文章中描述的那个,它修复了编译但是破坏了socket.io“on”功能(json对象不再被解释). 知道如何修复或忽略这个打字稿编译错误吗?
使用函数代替()=>
on(eventName:string,callback) { var self = this; this.socket.on(eventName,function() { var args = arguments; self.$rootScope.$apply(() => { callback.apply(self.socket,args); }); }); } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- Drupal_bootstrap:Connect to Drupal
- angular-cli6使用ng serve --o 控制台报错Invalid Host Hea
- [AngularJS面面观] 2. scope中的Dirty Checking(脏数据检查
- scala – Spark Implicit $for DataFrame
- 初始redis(第三步,安装redis,并输出hello redis)
- Bootstrap学习笔记(实习第2天)
- 将Scala SDK添加到Intellij中的所有模块
- angularjs – 如何检查我的元素是否集中在单元测试中
- vim – 在`vi`中的选择内查找和替换
- asp.net core 2.0 – 多个项目解决方案docker文件