I am new to 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.')
}
}
}
}
}
To throw an object literal, replace the round brackets with curly brackets: