extjs 在Chrome开发者工具中,对象前缀为“constructor”是什么意思?

ybzsozfc  于 2022-11-05  发布在  其他
关注(0)|答案(1)|浏览(169)

我正在使用ExtJs,我想获得所有Stores(应用程序的状态)的快照,所以我想我将遍历根Stores并收集每个data属性(前提是该值本身不是ExtJsStore)。
如果我检查开发人员控制台,我可以看到我想要的普通旧对象没有前缀constructor,但是StoresExtJs用来处理状态的类)前缀为constructor

我最初认为前缀为constructor与对象示例化的方式有关,但我无法使用以下任何一种方法来重现constructor前缀。

  1. > (function() {return {}})()
  2. < {}
  3. > class test {}
  4. < undefined
  5. > new test()
  6. < test {}
  7. > class test2 extends test{}
  8. < undefined
  9. > new test2()
  10. > test2 {}
  11. > new (function() {})
  12. < {}
  13. > function test3() {}
  14. < undefined
  15. > new test3()
  16. < test3 {}
  17. > Object.fromEntries(Array(20).fill(0).map((_, i) => [`${i}_someproperty`, "yeet"]))
  18. < {0_someproperty: "yeet", 1_someproperty: "yeet", 2_someproperty: "yeet", 3_someproperty: "yeet", 4_someproperty: "yeet", …}
  19. > {}
  20. < {}
  21. > (function(){return {}})()
  22. < {}

这意味着什么,或者如何检查Chrome开发人员控制台是否为对象指定了constructor前缀?

sf6xfgos

sf6xfgos1#

我不熟悉ExtJS,但在我看来,这很可能是某种泛型子类创建的结果,使用的函数碰巧总是命名为constructor,例如。

  1. function makeExtension(original) {
  2. // old-style prototype/constructor extension
  3. function constructor() {
  4. original.apply(...arguments);
  5. }
  6. constructor.prototype = Object.create(original.prototype);
  7. return constructor;
  8. }
  9. // old-style constructor
  10. function Foo() {}
  11. Foo.prototype.m = function() { console.log("hello world"); };
  12. let Bar = makeExtension(Foo);

在这种情况下,对象在控制台/检查器中的类型位置显示为“constructor”:

  1. > new Bar()
  2. < constructor {}
展开查看全部

相关问题