Created
May 30, 2013 22:13
-
-
Save ForbesLindesay/5681687 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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