首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >Immutable.js中的"ownerID“是什么?

Immutable.js中的"ownerID“是什么?
EN

Stack Overflow用户
提问于 2016-03-15 05:51:56
回答 1查看 2.2K关注 0票数 18

我正在查看Immutable.js的源代码,其中有一个我不理解的ownerID字段。

这是Map.asMutable()Map.asImmutable()的源代码:https://github.com/facebook/immutable-js/blob/master/src/Map.js#L171

似乎可变对象和不可变对象之间唯一的区别就是它们的ownerID。什么是ownerID,它是用来做什么的?

EN

回答 1

Stack Overflow用户

发布于 2016-03-24 11:54:44

source code

// A function which returns a value representing an "owner" for transient writes
// to tries. The return value will only ever equal itself, and will not equal
// the return of any subsequent call of this function.
function OwnerID() {}

我对上面的理解是this.__ownerID字段是用来比较对象的。与自身进行比较的Map将具有相同的ownerID,而与另一个Map进行比较的Map将看到两个不同的ownerID

您可以在little farther down in the file in question中查看此用法的示例

__ensureOwner(ownerID) {
  if (ownerID === this.__ownerID) {
    return this;
  }
  if (!ownerID) {
    this.__ownerID = ownerID;
    this.__altered = false;
    return this;
  }
  return makeMap(this.size, this._root, ownerID, this.__hash);
}

实际上,在searching the entire repo中,您将看到该函数在数据类型中是通用的,每种类型都有一个略微修改的版本,以返回该类型的正确新版本。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/35998781

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档