Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

[question] Node removeChild() set to null

未关闭
#375 6 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
38/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
停滞
技术栈
javascript
领域
frontend

调研方向

从 core/Node 中的 removeChild() 开始,将其对 _children 的处理与所报告代码片段中的 Dispatch.prototype.dispatch 进行比较。重现移除子节点后的事件分发,然后验证被移除的子节点不再导致对 null 的访问,同时保留预期的子节点列表行为;如果存在,检查 Node 和 dispatch 周围的现有测试。

由索引模型根据 Issue 内容生成。

描述

question

When Node1.removeChild(node2) is called, the index of node2 in Node1._children array is set to NULL.
This causes an error when, after a removeChild, i use events:

Uncaught TypeError: Cannot read property 'onReceive' of null

here:

Dispatch.prototype.dispatch = function dispatch (event, payload) {
if (!event) throw new Error('dispatch requires an event name as it's first argument');

var queue = this._queue;
var item;
var i;
var len;
var children;

queue.length = 0;
queue.push(this._context);

while (queue.length) {
    item = queue.shift();
    if (item.onReceive) item.onReceive(event, payload);
    children = item.getChildren();
    for (i = 0, len = children.length ; i < len ; i++) queue.push(children[i]);
}

};

I managed to fix this, by changing:

this._children[index] = null;

with:

this._children.splice(index, 1);

in the removeChild() function of core/Node.

Is this intentional?
Does this change affect other things?

主要语言
JavaScript
星标
1.7k
派生
249
PR 合并指标
30 天内没有已合并 PR

环境准备

  • 没有 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

Famous/engine 的其他 Issue

查看 Famous/engine 的全部 Issue

相似的 Issue

更多 JavaScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。