Copy private symbols from one object to another

# Nathan Wall (13 years ago)

Given the commonness of mixing one object into another, I was wondering how this would work with private symbols -- considering methods will expect to find those symbols on the objects on which they are called. Has there been any discussion about providing a way to copy private symbols "under the hood", so-to-speak, without having to know the symbols and without having them exposed? I imagine proxies might pose quite a problem to the second part, but I was just wondering if this problem had been addressed or if the mixin+symbol combo is just to be avoided.

# Brandon Benvie (13 years ago)

By design, private symbols can only be used if you have direct access to them in some way. Public symbols should show up in getOwnPropertyNames (if I have followed recent discussion correctly). The fact that private symbols must be explicitly passed around to gain access to them is their primary feature.

# Brendan Eich (13 years ago)

Brandon Benvie wrote:

By design, private symbols can only be used if you have direct access to them in some way.

Right.

Public symbols should show up in getOwnPropertyNames (if I have followed recent discussion correctly).

I don't recall this, and it's an incompatible change from ES5. Can you link to an es-discuss message on it?

The fact that private symbols must be explicitly passed around to gain access to them is their primary feature.

Yup.

# Brandon Benvie (13 years ago)

Ah I guess I misread what was said back in the July meeting and then misinterpreted the recent discussion in that framing. The recent discussion I'm referring to is at and around esdiscuss/2012-November/026536

# Brandon Benvie (13 years ago)

Or I guess to clarify, I don't understand what the distinction is between a private symbol and a unique symbol if unique symbols don't show up anywhere. So I jumped to the assumption that they did show up in gOPN based on what I read.

# Tom Van Cutsem (13 years ago)

2012/11/26 Brandon Benvie <brandon at brandonbenvie.com>

Or I guess to clarify, I don't understand what the distinction is between a private symbol and a unique symbol if unique symbols don't show up anywhere. So I jumped to the assumption that they did show up in gOPN based on what I read.

For sure, unique symbols should be query-able via reflection APIs. The only question is: do we introduce new API for them or do we naturally extend existing APIs (such as gOPN) to include them? I don't recall the discussion being definitively settled one way or the other.

# Brandon Benvie (13 years ago)

Yeah reading back for a refresher, it's definitely unsettled. The recent discussion about it linked above is all I see on it...thought there was something else.

# Allen Wirfs-Brock (13 years ago)

One way or another we need a way to reflectively identify all the non-private own property keys of an object including non-private symbols keys.

If we think the compat risk of adding symbols to the result of Object.getOwnProperyNames is too great (and we've recently discussed why this might not be much of a compat risk) then we need to add a new Object.getOwnPropertyKeys that does include them.