ES3 quasi incompatibilities
Kris Zyp
kriszyp at xucia.com
Fri Nov 9 09:20:04 PST 2007
> 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/4ae2b264/attachment-0002.html
More information about the Es4-discuss
mailing list