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

[ios] vue模式下,无法修改类的 toString 方法 #2334

Closed
Neeeo opened this issue Jan 19, 2017 · 7 comments
Closed

[ios] vue模式下,无法修改类的 toString 方法 #2334

Neeeo opened this issue Jan 19, 2017 · 7 comments

Comments

@Neeeo
Copy link
Contributor

Neeeo commented Jan 19, 2017

在iOS 设备上,修改类的 toString 方法会提示:

Cannot assign to read only property 'toString' of object

在游览器里没这个问题。用的sdk是从 dev 分支下自己编译的最新版。

复现代码:

<template>
  <div class="wrapper" @click="update">
    <image :src="logoUrl" class="logo"></image>
    <text class="title" v-if="!show">Good!! {{target}}</text>
    <text class="title" v-else-if="show">Bad!! {{target}}</text>
  </div>
</template>

<style>
  .wrapper { align-items: center; margin-top: 120px; }
  .title { font-size: 48px; }
  .logo { width: 360px; height: 82px; }
</style>

<script>
  export default {
    data: {
      logoUrl: 'https://alibaba.github.io/weex/img/[email protected]',
      target: 'World',
      show: true,
    },
    mounted: function() {
      debugger;
      var a = function() {

      };
      a.prototype.toString = function(){return 'hhhhhh';};
    },
    methods: {
      update: function (e) {
        this.target = 'Weex'
        console.log('target:', this.target)
      }
    }
  }
</script>
@Hanks10100
Copy link
Member

Hanks10100 commented Jan 19, 2017

与 Vue 无关,因为我们将 Object.prototype freeze 了,所以无法覆盖原型中的 toString 方法(如果实在想覆盖,可以用 Object.defineProperty)。参考 #1529

@Neeeo
Copy link
Contributor Author

Neeeo commented Jan 19, 2017

有个问题是,我用到的一个第三方库 url-parse 里重写了自己的 toString,导致现在用到它的地方都崩溃。
另外,为什么在 web 环境下没问题?

@Hanks10100
Copy link
Member

(如果你写的是 Vue 项目的话)在 Web 环境上是直接用 Vue.js 渲染的,不依赖于 Weex ,不含 Weex runtime 的代码,也就没 freeze 原型链。

@Hanks10100
Copy link
Member

将来很可能也会在 weex-vue-render 里把原生对象的原型 freeze 起来的。

@Neeeo
Copy link
Contributor Author

Neeeo commented Jan 19, 2017

顺便问一下,开 debugger 的时候,weex 对象找不到这个问题有解决办法吗?
#2314

@Hanks10100
Copy link
Member

@Neeeo 是 weex-toolkit 工具的问题,工具执行的时候会包上一层函数,没有把 weex 变量传进去,现在应该已经修掉了。

@dickeylth
Copy link
Contributor

@Neeeo url-parse 可以跟踪这个 pr: unshiftio/url-parse#54

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants