Well, there is a trick! If clone does not "clone" nested objects, you can force it to by explicitly cloning each object inside a map call! Like this:
#!/usr/bin/env node
var _ = require('underscore');
var a = [{f: 1}, {f:5}, {f:10}];
var b = _.map(a, _.clone); // <----
b[1].f = 55;
console.log(JSON.stringify(a));
Prints:
[{"f":1},{"f":5},{"f":10}]
Yay! a
is unchanged! I can now edit b
to my liking!
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…