Giter Club home page Giter Club logo

Comments (3)

jareguo avatar jareguo commented on May 18, 2024

奇怪的是这个问题在桌面上不是必现的。在手机上能必现。

from eruda.

surunzi avatar surunzi commented on May 18, 2024

getter 是设置在 cc.Node 的 prototype 上面,但这里判断用的 obj 是 cc.Node 的父类的 prototype

// getter设置在A的prototype上,B是A的父类
var B = function () {};
var A = function () { this._data = 'eruda' };
A.prototype = Object.create(B.prototype);
Object.defineProperty(A.prototype, 'data', {
    get: function () { return this._data }
});
var a = new A();
console.log(a);

不知我理解是否有误,上面代码在Chrome和safari ios试了结果并没有问题。能否给下在手机上出错的最小错误示例代码?

from eruda.

jareguo avatar jareguo commented on May 18, 2024

你的理解是正确的,我找到重现代码了,看来不是 eruda 的问题。

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
    <script type='text/javascript' src='./eruda.min.js'></script>
    <script type='text/javascript'>
        eruda.init();

        function Base () {}
        Object.defineProperty(Base.prototype, 'data', {
            get: undefined,
        });

        function Sub () {}
        Sub.prototype = Object.create(Base.prototype);

        Object.defineProperty(Sub.prototype, 'data', {
            get: function () {
                console.error('use prop over data');
            }
        });

        console.log(new Sub());
    </script>
</body>
</html>

运行以上网页,就会出现 use prop over data 的报错。
在这里 defineProperty 时,get 传入的是 undefined。虽然发生了继承,子类的 get 仍然无法覆盖基类的 undefined,property descriptor 永远只能拿到 { enumerable:false, get: undefined },不论基类是否启用 configurable 都会这样。

当然,这里基类的 get 一开始就不应该定义成 undefined。这是我们内部的错误。

from eruda.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.