Le 15/01/2013 19:19, Kevin Reid a écrit :
On Tue, Jan 15, 2013 at 2:20 AM, David Bruant <[email protected]
<mailto:[email protected]>> wrote:
Practice of the event loop model in JavaScript has proven that the
share-nothing model has limitations. In my opinion, one of the
reasons WebWorkers aren't used is that the share-nothing model
imposes to copy data when one wants 2 WebWorkers to communicate.
This resulted in the addition of Transferable objects in
JavaScript [1]. Rust introduced the notion of unique pointer [2]
for equivalent reasons.
From a capability viewpoint, there are non-performance reasons to have
the same pattern, even within a given event loop, namely resources
which may be transferred with observably exclusive access (ownership);
the pattern is to have an operation on the resource which generates a
new reference to it (i.e. a new object, from the OO perspective) and
makes the old one useless ("revoked").
Interesting. It reminds me that JavaScript does not have a notion of
internal and external code with regard to an object. Anyone with access
to the object can equivalently modify it (add, delete properties for
instance).
On object can't at the same time defend its integrity and modify its own
shape (I guess it's possible with proxies now).
I don't know why anyone would want to do that, but if you want to model
a caterpillar becoming a butterfly, it's a bit complicated in JavaScript
without proxies. The caterpillar has a "crawl" method and if we want the
same object (same identity) to eventually become a butterfly with a
"fly" method (but no crawl method), the object has to remain extensible
and the crawl property has to be configurable. The problem is that any
outsider can mess around with the properties.
The idea of generating a new object out of an old one which becomes
useless is interesting, but people holding a reference to the
caterpillar may expect to have a reference to a butterfly eventually.
The problem with a new identity is that people holding a reference to
the caterpillar now have a useless reference and may not hold the
reference to the butterfly.
Where have you seen the "create new object from old one" pattern used?
It sounds interesting, but I can't think of where I'd use it.
David
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss