[英]Error Using Socket.io Client Side Files in a Nodejs Project
I'm using Socket.io in my nodejs project. 我在我的nodejs项目中使用Socket.io。 In order to use socket.io I should use two javascript files in client side:
为了使用socket.io,我应该在客户端使用两个javascript文件:
The first one is socket.io-1.3.5.js 第一个是socket.io-1.3.5.js
The second one is a javascript file that exists in this local url: /socket.io/socket.io.js. 第二个是此本地URL中存在的javascript文件:/socket.io/socket.io.js。
As I understand, you should reference the first file before the second one. 据我了解,您应该在第二个文件之前引用第一个文件。 But this will result in an error when I run the server:
但这会在我运行服务器时导致错误:
Uncaught TypeError: object is not a function
And it's refering to this line of the second file: 它指的是第二个文件的这一行:
query[this.timestampParam] = +new Date + '-' + Transport.timestamps++;
I've installed socket.io. 我已经安装了socket.io。 What do I do?
我该怎么办?
Thanks. 谢谢。
The problem I had here, was a rather stupid one. 我在这里遇到的问题是一个相当愚蠢的问题。 The /socket.io/socket.io.js file and socket.io-1.3.5.js both use a Date class.
/socket.io/socket.io.js文件和socket.io-1.3.5.js都使用Date类。 I had written a script file in my project that also had a line like this:
var date = new Date()
which was being mixed up with the Date class that those two were using and was casuing this. 我在项目中编写了一个脚本文件,该文件也有这样的一行:
var date = new Date()
与这两个正在使用的Date类混合在一起并正在执行此操作。
It's highly unlikely that anyone encounteres the same problem, but similar cases might happen in any project so I decided to post this here. 任何人遇到相同问题的可能性都很小,但是在任何项目中都可能发生类似的情况,因此我决定在此处发布。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.