{"id":51018602,"url":"https://github.com/hlxuan/javascript-this","last_synced_at":"2026-06-21T14:01:20.142Z","repository":{"id":364574546,"uuid":"893010188","full_name":"Hlxuan/javascript-this","owner":"Hlxuan","description":"「JavaScript 编程基础」课程——this指向","archived":false,"fork":false,"pushed_at":"2026-06-13T14:37:28.000Z","size":13,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2026-06-13T16:23:57.186Z","etag":null,"topics":["javascript","this"],"latest_commit_sha":null,"homepage":"","language":"HTML","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/Hlxuan.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,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2024-11-23T09:45:51.000Z","updated_at":"2026-06-13T14:37:32.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/Hlxuan/javascript-this","commit_stats":null,"previous_names":["hlxuan/javascript-this"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/Hlxuan/javascript-this","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Hlxuan%2Fjavascript-this","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Hlxuan%2Fjavascript-this/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Hlxuan%2Fjavascript-this/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Hlxuan%2Fjavascript-this/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Hlxuan","download_url":"https://codeload.github.com/Hlxuan/javascript-this/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Hlxuan%2Fjavascript-this/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34610832,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-21T02:00:05.568Z","response_time":54,"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":["javascript","this"],"created_at":"2026-06-21T14:01:17.230Z","updated_at":"2026-06-21T14:01:20.135Z","avatar_url":"https://github.com/Hlxuan.png","language":"HTML","funding_links":[],"categories":[],"sub_categories":[],"readme":"# javascript-this（JavaScript函数this指向）\n![GitHub commit activity (branch)](https://img.shields.io/github/commit-activity/m/Hlxuan/javascript-this) ![GitHub issues](https://img.shields.io/github/issues/Hlxuan/javascript-this) ![GitHub Stars](https://img.shields.io/github/stars/Hlxuan/javascript-this)\n\n## 项目描述\n\n### [步骤0：验证函数调用时`this`指向的不同情况](00_this指向的实验.html)\n\n本步骤将理解`this`在`JavaScript`执行上下文中的指向规则。\n\n#### 预期结果\n- 直接调用`foo()`函数，`this`指向全局对象`window`；\n- 通过对象调用`obj.showThis`函数，`this`指向调用函数的对象。\n\n\n### [步骤1：验证不同场景下`this`的默认绑定规则](01_this绑定规则实验.html)\n\n本步骤将通过研究不同的场景来观察`this`指向的变化，包括普通函数调用、对象属性方法独立调用、高阶函数内部调用，以及严格模式下的函数调用。\n\n#### 预期结果\n- 普通函数独立调用，在非严格模式下，`this`指向全局对象`window`；在严格模式下，`this`为`undefined`；\n- 在对象内定义的方法独立调用`baz()`，`this`指向全局对象`window`；\n- 在高阶函数内部调用`obj.bar`，`this`指向全局对象`window`；\n- 在严格模式下，`this`为`undefined`；\n\n\n### [步骤2：验证`this`的隐式绑定规则](02_this隐式绑定实验.html)\n\n本步骤将探索`this`的隐式绑定规则。\n\n#### 预期结果\n- 在`obj.bar()`调用中，`this`指向调用函数的对象。\n\n\n### [步骤3：验证`this`在`new`调用下的绑定规则](03_this_new绑定实验.html)\n\n本步骤将探索`this`在`new`调用下的绑定规则。\n\n#### 预期结果\n- 使用`new`关键词调用`foo()`，`this`指向新创建的对象。\n\n\n### [步骤4：验证`this`的显式绑定规则](04_this显式绑定实验.html)\n\n本步骤将探索`this`的显式绑定规则。\n\n#### 预期结果\n- 调用`foo.call(obj)`，`this`被显式绑定指向对象`obj`；\n- 调用`foo.apply(123)`，数字会被自动封装成对应的Number对象。\n- 调用`foo.call(\"abc\")`，字符串会自动封装成对应的String对象。\n\n\n### [步骤5：验证`apply`和`call`的使用方法](05_apply_call实验.html)\n\n本步骤将在不同调用方式下改变`this`指向以参数传递的方式。\n\n#### 预期结果\n- 直接调用`foo(\"gkd\", 18, 1.88)`函数，`this`指向全局对象`window`，在严格模式下为`undefined`；\n- 使用`apply`调用`foo.apply(\"apply\", [\"kobe\", 30, 1.98])`，`this`指向字符串`apply`；\n- 使用`call`调用`foo.call(\"call\", \"james\", 30, 1.98)`，`this`指向字符串`call`；\n\n\n### [步骤6：验证`bind`方法的使用](06_bind方法实验.html)\n\n本步骤将学习`bind`方法的作用和使用方法。\n\n#### 预期结果\n- 使用`bind`方法绑定`this`指向，`this`指向绑定对象。\n\n\n### [步骤7：验证特殊场景中的`this`绑定](07_特殊场景this绑定实验.html)\n\n本步骤将研究定时器、事件监听器以及数组的`forEach`方法如何处理`this`指向`this`指向。\n\n#### 预期结果\n- 使用`setTimeout`绑定`this`指向，`this`指向全局对象`window`（在非严格模式下）；\n- 使用`addEventListener`和`onclick`绑定`this`指向，`this`指向绑定对象；\n- 使用`forEach`绑定`this`指向，`this`指向绑定对象。\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhlxuan%2Fjavascript-this","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhlxuan%2Fjavascript-this","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhlxuan%2Fjavascript-this/lists"}