{"action":"opened","issue":{"url":"https://api.github.com/repos/zhictory/frontend/issues/19","repository_url":"https://api.github.com/repos/zhictory/frontend","labels_url":"https://api.github.com/repos/zhictory/frontend/issues/19/labels{/name}","comments_url":"https://api.github.com/repos/zhictory/frontend/issues/19/comments","events_url":"https://api.github.com/repos/zhictory/frontend/issues/19/events","html_url":"https://github.com/zhictory/frontend/issues/19","id":343387480,"node_id":"MDU6SXNzdWUzNDMzODc0ODA=","number":19,"title":"传递参数","user":{"login":"zhictory","id":6872950,"node_id":"MDQ6VXNlcjY4NzI5NTA=","avatar_url":"https://avatars0.githubusercontent.com/u/6872950?v=4","gravatar_id":"","url":"https://api.github.com/users/zhictory","html_url":"https://github.com/zhictory","followers_url":"https://api.github.com/users/zhictory/followers","following_url":"https://api.github.com/users/zhictory/following{/other_user}","gists_url":"https://api.github.com/users/zhictory/gists{/gist_id}","starred_url":"https://api.github.com/users/zhictory/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zhictory/subscriptions","organizations_url":"https://api.github.com/users/zhictory/orgs","repos_url":"https://api.github.com/users/zhictory/repos","events_url":"https://api.github.com/users/zhictory/events{/privacy}","received_events_url":"https://api.github.com/users/zhictory/received_events","type":"User","site_admin":false},"labels":[{"id":1001005510,"node_id":"MDU6TGFiZWwxMDAxMDA1NTEw","url":"https://api.github.com/repos/zhictory/frontend/labels/JavaScript","name":"JavaScript","color":"ff69b4","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-07-22T08:17:58Z","updated_at":"2018-07-22T08:17:58Z","closed_at":null,"author_association":"OWNER","body":"```javascript\r\nvar trie = {};\r\n\r\nfunction add(newTrie, str) { // 构建一个newTrie\r\n  for (var i = 0, len = str.length; i < len; i++) {\r\n    var value = str[i];\r\n    if (newTrie[value] == null) {\r\n      newTrie[value] = {\r\n        val: value,\r\n        deep: i,\r\n        appearCount: 1\r\n      };\r\n    } else {\r\n      newTrie.appearCount++;\r\n    }\r\n    newTrie = newTrie[value];\r\n  }\r\n  newTrie = new Object();\r\n  console.log(trie);\r\n}\r\nadd(trie, \"banana\");\r\n```\r\n\r\n上面的例子中，将 trie 传递给函数 add，那么：\r\n\r\n1. 按值传递的话，当 newTrie 修改属性时，trie 会有相同的变化，当 newTrie = new Object() ，trie 不会改变，因为 newTrie 指向新对象地址了。\r\n2. 按引用传递的话，当 newTrie 修改属性时，trie 会有相同的变化，当 newTrie = new Object() 时，trie 会改变，因为修改了同个地址的对象。\r\n\r\n结果是第一种情况，所以传递参数是按值传递的。\r\n\r\n图解：[传递参数](https://www.processon.com/view/link/579acecbe4b03e26b9144312)\r\n\r\n![image](https://user-images.githubusercontent.com/6872950/43043652-c6af1230-8dca-11e8-9b5f-5243b268df2b.png)"}}
{"actor":{"display_login":"zhictory"}}