{"id":16582705,"url":"https://github.com/nodejh/professional_javascript_notes","last_synced_at":"2025-10-28T10:04:16.246Z","repository":{"id":90786541,"uuid":"76281905","full_name":"nodejh/professional_javascript_notes","owner":"nodejh","description":"📔 Professional JavaScript for Web Developers Reading Notes","archived":false,"fork":false,"pushed_at":"2017-03-24T06:42:46.000Z","size":20,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-10-28T10:04:01.226Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/nodejh.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-12-12T18:01:45.000Z","updated_at":"2017-03-24T06:42:47.000Z","dependencies_parsed_at":null,"dependency_job_id":"56ec59aa-d15f-41ca-96d7-aeaeaad73f76","html_url":"https://github.com/nodejh/professional_javascript_notes","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/nodejh/professional_javascript_notes","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nodejh%2Fprofessional_javascript_notes","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nodejh%2Fprofessional_javascript_notes/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nodejh%2Fprofessional_javascript_notes/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nodejh%2Fprofessional_javascript_notes/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nodejh","download_url":"https://codeload.github.com/nodejh/professional_javascript_notes/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nodejh%2Fprofessional_javascript_notes/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":281418054,"owners_count":26497723,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-28T02:00:06.022Z","response_time":60,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-11T22:33:48.942Z","updated_at":"2025-10-28T10:04:16.210Z","avatar_url":"https://github.com/nodejh.png","language":"JavaScript","readme":"# 《JavaScript高级程序设计读书笔记》\n\n\n## TODO\n\n+ 8.1.4 窗口大小，书上讲得不够清楚\n\n\n## ISSUE\n\n\n### P72 [已解决]\n\n主要是 JS 传递参数的方式。\n\n[https://github.com/nodejh/nodejh.github.io/issues/32](https://github.com/nodejh/nodejh.github.io/issues/32)\n\n```\nfunction setName(obj) {\n  obj.name = 'nodejh';\n  obj = new Object();\n  obj.name = 'jh';\n}\n\nvar person = new Object();\nsetName(person);\nalert(person.name); // nodejh\n```\n\n为什么是 nodejh？\n\n```\nfunction addTen(num) {\n  num += 10;\n  return num;\n}\n\nvar count = 20;\nvar result = addTen(count);\nalert(count); // 20, 没有变化\nalert(result); // 30\n```\n\n\n## 知识点\n\n#### 闭包\n\n+ [js闭包,垃圾回收,内存泄漏](https://segmentfault.com/a/1190000004682028)\n\n```\nfunction f1() {\n    var res = new Array();\n    for(var i=0;i\u003c10;i++){\n        res[i] = function() {\n            alert(i);\n        };\n    }\n    return res;\n}\nvar f2 = f1();\nvar f2 = f1();\nf2[0]();//alert 10\n//并不会返回一次弹出0-9的函数数组，而是弹出10个10的函数数组,因为res中每个函数的作用域中都保存着f1()的活动对象，引用的是同一个变量i，当f1()返回后i的值为10\n```\n\n```\nfunction f1() {\n    var res = new Array();\n    for(var i=0;i\u003c10;i++){\n        res[i] = (function(num) {\n            return function (){\n                alert(num);\n            }\n        })(i);//函数参数按值传递\n    }\n    return res;\n}\nvar f2 = f1();\nvar f2 = f1();\nf2[0]();//alert 0\n\n```\n\n#### 内存回收\n\n```\nwindow.onload = function(){\n    var ele = document.getElementById(\"id\");\n    ele.onclick = function(){\n        alert(ele.id);\n    }\n}\n```\n\n循环引用。\n\n```\nele.onclick = function(){\n  alert(ele.id);\n}\n```\n\n\n解决办法：\n\n```\nwindow.onload = function(){\n    var ele = document.getElementById(\"id\");\n    var id = ele.id; //解除循环引用\n    ele.onclick = function(){\n        alert(id);\n    }\n    ele = null; // 将闭包引用的外部函数中活动对象清除\n}\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnodejh%2Fprofessional_javascript_notes","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnodejh%2Fprofessional_javascript_notes","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnodejh%2Fprofessional_javascript_notes/lists"}