using the following constructor in the parse function throws an exception:
new Function("args", body);
"Uncaught SyntaxError: Unexpected identifierkendo.data.DataSource.schema.parse @ KendoWorklist?processId=1:257g.extend.success @ kendo?v=eOyB53xLlSdFHOrBbggvVxenL4FmfrA-viibHS3DbGs1:1g.extend.read.i._queueRequest.i.online.i.transport.read.success @ kendo?v=eOyB53xLlSdFHOrBbggvVxenL4FmfrA-viibHS3DbGs1:1vt.extend.read.i.success @ kendo?v=eOyB53xLlSdFHOrBbggvVxenL4FmfrA-viibHS3DbGs1:1i.Callbacks.a @ jquery?v=FVs3ACwOLIVInrAl5sdzR2jrCDmVOWFbZMY6g6Q0ulE1:1i.Callbacks.h.fireWith @ jquery?v=FVs3ACwOLIVInrAl5sdzR2jrCDmVOWFbZMY6g6Q0ulE1:1k @ jquery?v=FVs3ACwOLIVInrAl5sdzR2jrCDmVOWFbZMY6g6Q0ulE1:1i.ajaxTransport.send.u @ jquery?v=FVs3ACwOLIVInrAl5sdzR2jrCDmVOWFbZMY6g6Q0ulE1:1"
why would the new Function constructor not work in the parse function?
5 Answers, 1 is accepted
the reason I want to use the new Function() constructor is because I send my data over normalized and the most efficient way to denormalize it is as follows:
I think both solutions have the same complexity O(N*M);
Where N is the count of the data.
And M is the count of the fields.
Additionally the const of the both approaches is pretty much the same.
The difference is that in first approach you iterate the properties and build the object yourself. And in the second approach you pass some big constructor for this object, and the JS engine parses the values and then the browser do the same: iterate them and build the object.
If you perform some test, you will get very similar times in both large and small set of data. Here is some code based on yours:
The times that I get are 2.478s for the first function and 2.264 for the second for this very big set of data. For small set of data they work practically the same.
From profiling in chrome it seems that the difference comes mainly from execution of the garbage collector more often in the first function.
So you can use the working approach without any worries. I will additionally debug why the second one fails when passed as a parse function.
also instead of concatenating with "+=" I should've used ".concat()"
with this change f2() is much master than f1()
Interesting is that in Firefox (Nightly Builds) the solution 2 is actually slower than solution 1.
Back to the original subject. I tried to get the same error as you, but in my case it is working correct, even with your original code.
Here is testing example in our dojo:
When I run it I get the alert displaying the name and age of the first record. And looking at the console, there is no exception like described.
What I see here as the potential problem if the fields contains numbers without literal prefix.
For example if the field is called "123" instead of "name". Then you will get exception when evaluating function like:
"this.123 = something".
however the first solution will work:
this = something
Could you check the example code above, and tell me what is different in your case. You can edit the example and write here the new link you get.