Skip to content
This repository has been archived by the owner on Jan 23, 2021. It is now read-only.

Does not work with sealed objects #2

Closed
nhardy opened this issue Sep 30, 2015 · 2 comments
Closed

Does not work with sealed objects #2

nhardy opened this issue Sep 30, 2015 · 2 comments

Comments

@nhardy
Copy link

nhardy commented Sep 30, 2015

See ES6 Code below:

class Model {
  constructor(props) {
    this.init();

    Object.seal(this);

    if (props) {
      deepAssign(this, props);
    }
  }

  init() {
    Object.defineProperties(this, {
      one: {
        value: null,
        writable: true,
        enumerable: true
      },
      two: {
        value: {},
        writable: true,
        enumerable: true
      }
    });
    Object.defineProperties(this.two, {
      three: {
        value: null,
        writable: true,
        enumerable: true
      },
      four: {
        value: null,
        writable: true,
        enumerable: true
      }
    });
  }
}

console.log(new Model({one: 'foo', two: {three: 'bar', four: 'baz', five: 'shouldn\'t appear'}, six: 'won\'t appear'}));
@sindresorhus
Copy link
Owner

What exactly is not working? What did you expect? Please provide a simpler example, preferably a failing test.

@sindresorhus sindresorhus changed the title Does not work with sealed objects. Does not work with sealed objects Sep 30, 2015
@schnittstabil
Copy link
Contributor

@nhardy Your code works exactly as intended:

  1. Object.seal preventing six from being added
  2. Object.seal marking two as non-configurable, but that does not mean you can't add a new property to two (see Object.defineProperty for details about configurable)

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

No branches or pull requests

3 participants