to be clear: no, Object.assign does not copy accessors in a meaningful way,
it copies the result of the getter, not its descriptor.

That page at MDN has also many errors, including the function myAssign that
copies keys but not Symbols.

Gonna fix that, best regards

On Tue, Jan 19, 2016 at 1:16 PM, 森建 <[email protected]> wrote:

> @Thomas
>
> >Could this be achieved with decorators?
>
> I want to get Syntax Sugar.
> But I didn't have an idea using decorators, thank you!
>
>
> @kdex
>
> >About your nomenclature: Why name it `protected` rather than `private`?
> Am I missing a key difference between the two here?
>
> This is not `private` proposal, because `class B extends A` can call
> `getName()` in `class Protected_A`, like below.
>
> ```js
> class B extends A {
>
>     constructor(name, lastName, age) {
>         super(name, lastName);
>
>         // protected this
>         if(new.target === B)    _(this, Protected_B);
>
>         // protected property
>         _(this).age = age;
>     }
>
>     callGetAge() {
>         return _(this).getAge();
>     }
>
>     // added
>     getData() {
>         return {
>             name: _(this).getName(); // Protected_A
>             age:  _(this).getAge();
>         }
>     }
>
> }
> ```
>
> I'm sorry that my JavaScript code in ES2015 is too vain complex to
> understand.
>
>
> @Andrea Giammarchi
>
> >On a side note, that `Object.assign` operation doesn't do what you
> think it does, there are better patterns (boilerplates, actually ...) to
> copy own properties over within their descriptors, if different from
> enumerable data descriptors.
>
> I didn't know boilerplates, thank you!
> But `Object.assign` enable to copy accessors by using
> `Object.getOwnPropertyDescriptor` according to (MDN sample
> code)[
> https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign
> ].
>
> Of course, this approach must be bad...
>
> Note: In case, `Object.getOwnPropertyDescriptors` proposal (Stage 0) in
> ES2016 isn't same as `Object.getOwnPropertyDescriptor`. I misunderstood it.
>
> >P.S. the amount of wm.set(a, b).get(a) operations instead of wm.set(a,
> b) returning b is too damn high ... I know, I know, old discussion is
> old (and too late anyway)
>
> Sorry, it's my corner-cutting. I didn't know the amount, thank you!
> _______________________________________________
> 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