Skip to content

Instantly share code, notes, and snippets.

@ForbesLindesay
Created May 30, 2013 22:13
Show Gist options
  • Save ForbesLindesay/5681687 to your computer and use it in GitHub Desktop.
Save ForbesLindesay/5681687 to your computer and use it in GitHub Desktop.
var Q = require('q')
function deep(object) {
return Q.when(object, function (object) {
if (typeof object !== "object" || object === null || object instanceof Date) {
return object;
} else {
var synchronize;
for (var i in object) {
if (Object.prototype.hasOwnProperty.call(object, i)) {
(function (i, value) {
synchronize = Q.when(synchronize, function () {
return Q.when(deep(value), function (value) {
object[i] = value;
});
});
})(i, object[i]);
}
}
return Q.when(synchronize, function () {
return object;
});
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment