Javascript Nowjs:[RangeError:超出最大调用堆栈大小]
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10828073/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Nowjs: [RangeError: Maximum call stack size exceeded]
提问by timidboy
When I start the server on port 8080 it doesn't give me an error, but when I am trying to browse the http://localhost:8080/nowjs/now.js
the server raises an error:
当我在端口 8080 上启动服务器时,它不会给我一个错误,但是当我尝试浏览http://localhost:8080/nowjs/now.js
服务器时,会引发一个错误:
[RangeError: Maximum call stack size exceeded]
undefined
[RangeError: Maximum call stack size exceeded]
undefined
I tried the same with socket.io and it worked fine.
我用 socket.io 尝试了同样的方法,效果很好。
回答by Zlatko
Hmm, if now.js uses date.js, maybe your issue lies here. What the link says is that date.js tries to set a toString to Date prototype, but when toString is already defined, you get the circular referencementioned in the other answers.
嗯,如果 now.js 使用 date.js,也许你的问题出在这里。链接说的是 date.js 尝试将 toString 设置为 Date 原型,但是当 toString 已经定义时,您会得到其他答案中提到的循环引用。
Basically, they say that in date.js, you change
基本上,他们说在 date.js 中,你会改变
Date.prototype._toString=Date.prototype.toString
to
到
if(Date.prototype._toString==undefined) {Date.prototype._toString=Date.prototype.toString;}
I hope it will help someone. It helped me.
我希望它会帮助某人。它帮助了我。
回答by Rohan Durve
Aadit, have you read the following:
Aadit,您是否阅读了以下内容:
Maximum Call Stack Size Exceeded During a setTimeout Call
Uncaught RangeError: Maximum call stack size exceeded, JavaScript
未捕获的 RangeError:超出最大调用堆栈大小,JavaScript
So, as you may see the problem seems to be arising because of the an improper use of stack sizes. If you haven't already you may read a bit more about this problem in detail here along with a possible solution: Maximum call stack size exceeded error
因此,正如您所看到的,问题似乎是由于堆栈大小使用不当而引起的。如果您还没有阅读更多有关此问题的详细信息以及可能的解决方案: 最大调用堆栈大小超出错误
I don't think it has anything to do with the port, more with the methods/functions in the manner you're interacting/using the stack.
我认为它与端口没有任何关系,更多地与您交互/使用堆栈的方式/函数有关。
Then again, I may be wrong. ;D
再说一次,我可能错了。;D
回答by Kato
I've had two problems with now.js that produce this error message. Hopefully one of them will help you.
我在使用 now.js 时遇到了两个问题,会产生此错误消息。希望其中之一可以帮助您。
Circular References
循环引用
You cannot include any circular references in objects passed into now, or it's extend method will barf. There were some optimizations and workarounds for this and it's now listed as an closed issue, but I have run into it.
你不能在现在传入的对象中包含任何循环引用,否则它的扩展方法将失败。对此有一些优化和解决方法,现在它 被列为一个已解决的问题,但我遇到了它。
initialize() only once
initialize() 仅一次
Second, you may not call require('now').initialize(...)
twice or the two instances have a little intellectual conversationand race each other right out of the stack.
其次,您可能不会调用require('now').initialize(...)
两次,或者两个实例进行一些智力对话并在堆栈外相互竞争。
What I did instead was to create everyone
in app.js and pass it into all my require(...) methods that need to reference the now "pocket".
我所做的是everyone
在 app.js 中创建并将其传递到我所有需要引用现在“口袋”的 require(...) 方法中。
In /app.js:
在 /app.js 中:
var conf = {
everyone: require('now').initialize(app)
port: 3000,
// etc...
};
require('./routes')(conf)
// etc...
In routes/index.js:
在路由/index.js 中:
module.exports = function(conf) {
var everyone = conf.everyone;
return {
send: function() {
everyone.now.clientFxn(...);
}
}
}