es-membrane icon indicating copy to clipboard operation
es-membrane copied to clipboard

Dry and wet objects distinguishable by their prototype

Open LucaFranceschini opened this issue 6 years ago • 4 comments

If wrapping a (plain empty) object in a membrane, dry and wet objects have different prototypes. Besides being distinguishable through Object.getPrototypeOf, they usually are logged as different strings. Example with the Node.js REPL:

> wet
{}
> dry
rv {}

Is there any option I can pass to the membrane constructor to smooth this difference, or is this inevitable?

LucaFranceschini avatar Mar 02 '18 20:03 LucaFranceschini

If you want the membrane to be reasonably transparent, it is inevitable.

erights avatar Mar 02 '18 22:03 erights

There might be some things you can do - such as providing an alternate toString() method - but I think at this stage of development, it's premature to put that into the Membrane library itself.

I'm willing to be persuaded otherwise.

ajvincent avatar Mar 03 '18 00:03 ajvincent

Okay, I just did not know a new prototype was needed. Thanks for your replies.

(out of curiosity, since I am getting interested in proxies and membranes: what is it that cannot be done by the proxy handlers alone?)

LucaFranceschini avatar Mar 06 '18 15:03 LucaFranceschini

That... is a very good question. One I don't have a clear answer to.

First off, the question should be rephrased: what can't a proxy or proxy handler do that an object can? JavaScript doesn't support operator overloading on objects, for example, nor on proxies. Which is a shame, in my opinion.

I think that proxies can do at least as much as objects can. More specifically, I haven't found anything that doesn't meet that criteria.

That said, I think JavaScript arrays specifically, and containers more generally, need to be carefully considered in the membrane model. For instance, if you simply hide the second element in an array through a membrane, the receiver of that array will not be pleased to have the look-up array[1] either return undefined or throw an error.

I hope to give a talk on this library in late July, at the TC39 meeting in Redmond, WA. If so, arrays will definitely be one of the points I raise, as an unsolved problem.

ajvincent avatar Mar 06 '18 20:03 ajvincent