Coder Social home page Coder Social logo

Class constructor about structure HOT 4 CLOSED

talyssonoc avatar talyssonoc commented on June 18, 2024
Class constructor

from structure.

Comments (4)

talyssonoc avatar talyssonoc commented on June 18, 2024

Hello, @loweoj,

yeah, I didn't notice that when it was developed. The problem happens because when you try to set a value for the attribute inside the constructor, this will still be undefined: https://github.com/talyssonoc/structure/blob/master/src/attributes/descriptors.js#L25

A solution I can think for that is to always check if this[ATTRIBUTES] exists and, if no, set a value for that inside the getter. I'm not sure about the performance of that conditional tho (shouldn't be a problem). What do you think?

from structure.

loweoj avatar loweoj commented on June 18, 2024

You mean modify the setter for an attribute?

We just need instance[ATTRIBUTES] = Object.create(null); to be called before the instance constructor, or before attempting to set an attribute.

from structure.

talyssonoc avatar talyssonoc commented on June 18, 2024

That's the problem, we don't have an instance to assign it before the instance constructor. I mean modifying the getter of instance.attributes (which delegates to instance[ATTRIBUTES]) so it'll be always present.

from structure.

talyssonoc avatar talyssonoc commented on June 18, 2024

Hello, @loweoj! I've been working on Structure v2 (it's already in alpha in case ou wanna test) and I was thinking about a solution for that in v2. Would your proposed solution in #100 work for attributes with dynamic defaults, mainly if these dynamic defaults access instance methods?

from structure.

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.