{"action":"created","issue":{"url":"https://api.github.com/repos/cjohansen/Sinon.JS/issues/665","labels_url":"https://api.github.com/repos/cjohansen/Sinon.JS/issues/665/labels{/name}","comments_url":"https://api.github.com/repos/cjohansen/Sinon.JS/issues/665/comments","events_url":"https://api.github.com/repos/cjohansen/Sinon.JS/issues/665/events","html_url":"https://github.com/cjohansen/Sinon.JS/issues/665","id":55845795,"number":665,"title":"Proposal: Argument snapshots","user":{"login":"BigstickCarpet","id":3453903,"avatar_url":"https://avatars.githubusercontent.com/u/3453903?v=3","gravatar_id":"","url":"https://api.github.com/users/BigstickCarpet","html_url":"https://github.com/BigstickCarpet","followers_url":"https://api.github.com/users/BigstickCarpet/followers","following_url":"https://api.github.com/users/BigstickCarpet/following{/other_user}","gists_url":"https://api.github.com/users/BigstickCarpet/gists{/gist_id}","starred_url":"https://api.github.com/users/BigstickCarpet/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/BigstickCarpet/subscriptions","organizations_url":"https://api.github.com/users/BigstickCarpet/orgs","repos_url":"https://api.github.com/users/BigstickCarpet/repos","events_url":"https://api.github.com/users/BigstickCarpet/events{/privacy}","received_events_url":"https://api.github.com/users/BigstickCarpet/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":4,"created_at":"2015-01-29T02:03:06Z","updated_at":"2015-01-29T15:16:04Z","closed_at":null,"body":"[Other](https://github.com/cjohansen/Sinon.JS/issues/571) [issues](https://github.com/cjohansen/Sinon.JS/issues/583) have already been raised about the fact that Sinon stores arguments by reference, which means they can be changed between the time the spy is invoked and the time we assert on it.   Per @mroderick, the decision seems to be that this is by-design and storing arguments by value would cause all sorts of other problems. \r\n\r\nAgreed.  But I have a proposal that could work for everyone.   Leave the current `spy.args` property as it is (by reference), but add a `spy.snapshot` property that contains [deep clones](https://lodash.com/docs#cloneDeep) of each argument _at the time the spy was invoked_.   Here's an example:\r\n````javascript\r\nfunction changeName(person) {\r\n    person.name = 'Billy Bob';\r\n}\r\n\r\nvar spy = sinon.spy(changeName);\r\nspy({name: 'John Doe'});\r\n\r\n// spy.args is by-reference, so the \"name\" property has been changed\r\nassert.equal(spy.args[0][0].name, 'Billy Bob');\r\nassert.equal(spy.firstCall.args[0].name, 'Billy Bob');\r\n\r\n// spy.snapshot is by-value, so the \"name\" property is as it was when the spy was called\r\nassert.equal(spy.snapshot[0][0].name, 'John Doe');\r\nassert.equal(spy.firstCall.snapshot[0].name, 'John Doe');\r\n````"},"comment":{"url":"https://api.github.com/repos/cjohansen/Sinon.JS/issues/comments/72041169","html_url":"https://github.com/cjohansen/Sinon.JS/issues/665#issuecomment-72041169","issue_url":"https://api.github.com/repos/cjohansen/Sinon.JS/issues/665","id":72041169,"user":{"login":"mantoni","id":332271,"avatar_url":"https://avatars.githubusercontent.com/u/332271?v=3","gravatar_id":"","url":"https://api.github.com/users/mantoni","html_url":"https://github.com/mantoni","followers_url":"https://api.github.com/users/mantoni/followers","following_url":"https://api.github.com/users/mantoni/following{/other_user}","gists_url":"https://api.github.com/users/mantoni/gists{/gist_id}","starred_url":"https://api.github.com/users/mantoni/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mantoni/subscriptions","organizations_url":"https://api.github.com/users/mantoni/orgs","repos_url":"https://api.github.com/users/mantoni/repos","events_url":"https://api.github.com/users/mantoni/events{/privacy}","received_events_url":"https://api.github.com/users/mantoni/received_events","type":"User","site_admin":false},"created_at":"2015-01-29T15:16:04Z","updated_at":"2015-01-29T15:16:04Z","body":"True. But it would also work with `calledWith` and friends."}}