ES3 quasi incompatibilities
Lars Hansen
lhansen at adobe.com
Fri Nov 9 10:00:31 PST 2007
Map and intrinsic::hashcode are your friends, indeed. Cleaner solution,
too.
<rambling>
For non-dynamic classes you can still use meta::set and meta::get to
allow for
limited applications like this. I keep thinking that there are use
cases for
global meta::get and meta::set functions, so just like operator
overloading
can be done by extending global, generic functions a la intrinsic::+, it
ought to
be possible to hook into catchalls on the global level, using generic
functions.
class C { ... } // not dynamic
meta generic function get(c: C, name) {
if (name == "__marker")
...
else
return nextMethod()
}
meta generic function set(c: C, name, val) {
if (name == "__marker")
...
else
nextMethod()
}
</rambling>
--lars
________________________________
From: es4-discuss-bounces at mozilla.org
[mailto:es4-discuss-bounces at mozilla.org] On Behalf Of Kris Zyp
Sent: 9. november 2007 09:20
To: es4-discuss at mozilla.org
Subject: ES3 quasi incompatibilities
> or whether ES4 precludes the use of current ES3 AOP patterns
and how
> that might be solved. Among other things.)
ES3 AOP is in a class of patterns that is not strictly
incompatible as ES3 code alone won't break, but ES3 code would no longer
behave as expected when interacting with ES4 code. AOP and other
patterns in ES3 rely on the ability to add or modify properties on any
object. Another example that should be noted is the O(n) algorithm for
duplicate item and cyclic reference detection. For example:
function findDuplicate(array){
var map={};
for (var i = 0; i < array.length; i++) {
if (typeof array[i] == 'object') {
if (array[i].__marker)
alert('found duplicate');
array[i].__marker = true;
}
else {
if (map[array[i]])
alert('found duplicate');
map[array[i]] = true;
}
}
}
This algorithm will fail if an array of objects is passed in
that includes instances of non-dynamic (default for user created)
classes. Temporarily marking objects with dynamic properties is the only
way I am aware of to create O(n) algorithms in ES3 to detect duplicates
and cyclic references.
I don't think there is anything that can be done about this, it
is just a result of static classes. Code written for ES4 can use maps (I
think anyway) to solve this problem. This has probably already been
discussed, but I just wanted to make sure it was noted.
Kris
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.mozilla.org/pipermail/es-discuss/attachments/20071109/3ea8b208/attachment-0002.html
More information about the Es4-discuss
mailing list