[英]Javascript syntax--what am I doing wrong?
I am new to javascript. 我是javascript新手。 I have two documents--an old and a new--that I am comparing.
我正在比较两个文件-旧文件和新文件。 However, I am getting a syntax error somewhere in the code below.
但是,我在下面的代码中出现语法错误。
Somewhere in here, my code is blowing up. 在这里的某个地方,我的代码崩溃了。 The error says "expression does not eval to a function."
错误显示“表达式不等于函数”。 Any syntactic ideas of where I'm writing an incorrect statement?
关于我在哪里写错语句的任何句法观念?
if(userCtx.name != oldDoc.Document.attributeA) {
for (var key in oldDoc.Document)
{
if(newdoc.Document.hasOwnProperty('key')
{
if(oldDoc.Document[key] != newDoc.Document[key])
{
if(key === 'attributeB')
{
return;
}
else
{
throw(forbidden: 'Only admins may change this field.')
}
}
}
}
}
if(newdoc.Document.hasOwnProperty('key') <-- I am missing a )
To throw an object literal, replace the round brackets with curly brackets: 要抛出对象文字,请用大括号替换圆括号:
throw {
forbidden: 'Only admins may change this field.'
};
Is the code you posted inside of a function definition? 您发布的代码是否在函数定义中? I've seen that error when defining functions that get passed as arguments to something else, and forgotten to wrap the function in parenthesis.
在定义作为参数传递给其他函数的函数时,我已经看到了该错误,并且忘记了将该函数用括号括起来。 For example:
例如:
"compare": "function(docA, docB) { ... }"
should be: 应该:
"compare": "(function(docA, docB) { ... })"
And possibly one more... Is this inside a function? 可能还有一个...这是函数内部吗? If not you might be getting an error on the
return;
如果不是,您可能会在
return;
出错return;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.