Michael Haufe (TNO) wrote:
> With the language being as fast and loose as it is, (plus proxies now
> and interactions between differing versions of the language in the
> same document), you're just about shit out of luck I think for a 100%
> guarantee on identity and capability for objects you don't control.
> Any test (or combination thereof) will be little more than
> probabilistic test. Using the constructor property can also be
> considered a duck-typing check.
I do not see a reason why the “constructor” property value should be mutable
in the first place. If it were not, it could at least provide for efficient
tests where neither inheritance nor frame safety were issues.
> In the past I've espoused instanceof strongly over other methods if you
> might recall. You could simply follow the Self/SmallTalk tradition and
> simply act as if it WAS a RegExp until it explodes...
My thoughts exactly. In languages as dynamic as ECMAScript implementations
it is a mistake _not_ to delegate at least a part of the responsibility for
proper input to the caller (do I need to cite evidence for the bloat created
by following the opposite approach?). Not only would that be more likely to
produce false negatives, it would also miss the opportunity to make use of
language power and elegance.
In the case of references to RegExp instances, though, where inheriting from
their prototype does not make sense and so all pertinent objects have
[[Class]] "RegExp", in JSX:regexp.js I have switched from comparison against
the “constructor” property value to jsx.object.getClass() for the next
revision, for cross-view referencing.
It is unfortunate that almost everything in ECMAScript hinges on the Global
Object of an execution context, that there are several global execution
contexts, and that thereby the Specification forces its conforming
implementations to be in such a way that methods like Array.isArray() are
needed for the classification of objects in the first place. It should not
be necessary to have several RegExp objects just because there are several
views (frames, windows, tabs).
A quick solution would be if there was a superglobal object that all native
objects had in their prototype chain, or all global execution contexts had
in their scope chain, so that “foo instanceof RegExp” would work regardless
of callee and caller views as long as they were of the Same Origin. The
global object of execution contexts would then only have properties specific
to that execution context and would delegate everything else to the
superglobal object.
--
PointedEars
Twitter: @PointedEars2
Please do not Cc: me. / Bitte keine Kopien per E-Mail.