You are talking about "flatting" all properties, which is an undesired
overhead.

```js

var b = Object.create(
  Object.getPrototypeOf(a)
);

Object.assign(b, a);

```

But what's bugging me every time more, is that somebody had a very bad idea
to spread `Object.assign` as something good for inheritance or object
cloning.

Where does this come from? `Object.assign` retrieves properties and ignore
getters and setters, is the last tool you want to use as substitution
principle because it breaks.

`Object.assign` is good only to define enumerable, writable, and
configurable properties, like configuration or setup objects.

Are you dealing with prototypes and `Object.assign` ? You gonna have way
more problems than a missed flattered structure.

Can you explain what is your goal ? Wouldn't this work?

```js

var a = {}; // or anything else

var b = Object.create(
  Object.getPrototypeOf(a)
);

Object.getOwnPropertyNames(a).forEach(function (k) {
  Object.defineProperty(b, k, Object.getOwnPropertyDescriptor(a, k));
});

```


Best Regards



On Fri, Feb 27, 2015 at 11:52 AM, Andri Möll <[email protected]> wrote:

> Hello,
>
> Why does Object.assign ignore inherited enumerable properties?
> What is the problem to which ignoring inherited properties is the solution
> to?
>
> All I can see is that it prevents a useful use of inheritance. The Liskov
> substitution principle
> <https://en.wikipedia.org/wiki/Liskov_substitution_principle> was
> mentioned 27 years ago in ’87. Why is Object.assign breaking it?
>
> - Everyone who’s messing with Object.prototype has to do it an
> non-enumerable style anyway.
> - Most uses of Object.assign will likely be for objects with a finite
> number of keys. Those form specific and implicit types from which people
> are likely to read with the dot-operator. That takes inheritance into
> account anyway.
>
> I don’t get the agenda to mess with object inheritance. If one wants
> methods to only be in the parent and data on the child (so Object.assign
> would only copy data), use a classical language. In a delegation-prototypal
> language one should be able to inherit freely because of LSP
> <https://en.wikipedia.org/wiki/Liskov_substitution_principle>.
>
> Andri
>
> _______________________________________________
> es-discuss mailing list
> [email protected]
> https://mail.mozilla.org/listinfo/es-discuss
>
>
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to