Wednesday, 14 August 2013

Blocking the event loop with for..in

Blocking the event loop with for..in

I would like to check a Javascript Object for unwanted properties with a
schema definition for revalidator
(https://github.com/flatiron/revalidator).
I came up with following snippet:
function strip(object, schema) {
var strippedObject = {};
for (var property in schema.properties) {
if (schema.properties[property].type === 'object') {
strippedObject[property] = strip(object[property],
schema.properties[property]);
} else {
strippedObject[property] = object[property];
}
}
return strippedObject;
}
This code copies the wanted properties and loops synchronously over the
schema recursing into nested schemas.
I'm worried about blocking the event loop in this time.
Is this negligible as I'm not doing I/O?

No comments:

Post a Comment