Array.sort doesn't work properly when called twice?
问题 I've been playing this for a while. Why is val_a changed when I run the function to sort val b? How can I get around this? When I run the function separately they work, but when I run them together something goes wrong somewhere. var GLOBALS = {"items":[]}; var val_a; var val_b; GLOBALS.items=[ {"thing":"one","val_a":0.5,"val_b":0.2}, {"thing":"two","val_a":0.2,"val_b":0.3}, {"thing":"three","val_a":0.3,"val_b":0.1}]; val_a = GLOBALS.items.sort(function (a, b) { a=parseFloat(a.val_a); b