Git Product home page Git Product logo

Comments (4)

AlexAPPi avatar AlexAPPi commented on May 30, 2024

This also applies to other complex types: vec2, entity, ...

from engine.

marklundin avatar marklundin commented on May 30, 2024

Thanks @AlexAPPi, you've hit on an important point.

When an ES6 class members is defined, it is non configurable. Currently ScriptAttribute attempts to redefine the member using Object.defineProperty which effectively becomes a no-op. This prevents the type conversion and attribute events from working.

class Test { fail = 'should be overridden' }
Object.defineProperty(Test.prototype, 'fail',  { value: 100 });
test = new Test()
console.log(test.fail) // 'should be overridden'

I've created an editor repro here

For the time being, you'll need to avoid declaring attribute in the class body, or alternatively use the var MyClass = pc.createScript syntax. We plan on solving this limitation with the newer ESM Scripts

from engine.

LeXXik avatar LeXXik commented on May 30, 2024

At the moment, the issue can be very obscure, as it doesn't warn the developer. This can lead to bugs that are hard to debug. We should add a warning.

from engine.

marklundin avatar marklundin commented on May 30, 2024

Yep this is not ideal, but unfortunately I don't think this is possible to catch at run-time without instantiating the class first. A solution is to prevent users using the class notation or declaring members in the class body. Neither are ideal.

from engine.

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.