Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

子应用执行apply后不符合正常程序预期 #102

Closed
Heath1998 opened this issue Aug 28, 2022 · 1 comment
Closed

子应用执行apply后不符合正常程序预期 #102

Heath1998 opened this issue Aug 28, 2022 · 1 comment
Labels
bug Something isn't working

Comments

@Heath1998
Copy link
Contributor

Heath1998 commented Aug 28, 2022

描述bug
子应用下使用如下代码,输出结果不合预期。结果为undefined,预期结果为'test'字符串

如何复现

<script>
    const object = {};
    window.addAttributeToObject = function () {
      this.a = "test";
    };
    window.addAttributeToObject.apply(object);
    console.log(object.a); // undefined
  </script>

错误截图

最小复现仓库或者地址

@Heath1998 Heath1998 changed the title apply后不符合正常程序预期 子应用执行apply后不符合正常程序预期 Aug 28, 2022
@yiludege yiludege added the bug Something isn't working label Aug 28, 2022
@yiludege
Copy link
Collaborator

yiludege commented Aug 28, 2022

这个问题是由于 window 被 proxy 引起的,目前解决的思路是在对 window 的 某个 propety 做 set 的时候,满足一定条件(必须是函数且满足getTargetValue内部的那个条件)时,给这个函数 设置一个 私有属性 __xxx、或者存入一个map当中,下次 get 的时候判断存在__xxx或者在map中,在 getTargetValue 中直接返回

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants