David Mark wrote:
> Thomas 'PointedEars' Lahn wrote:
>> David Mark wrote:
>>> Thomas 'PointedEars' Lahn wrote:
>>>> David Mark wrote:
>>>>> Thomas 'PointedEars' Lahn wrote:
>>>>>> David Mark wrote:
>>>>>>> Why not just do this in the global context:-
>>>>>>>
>>>>>>> var global = this;
>>>>>>>
>>>>>>> ...and call it a day. 
>>>>>>>
>>>>>>> That's what I did in My Library, which has no unqualified - window
>>>>>>> - references. Come to think of it, it has no such _qualified_
>>>>>>> references
>>>>>>> either, which I don't consider ideal. So as not to assume that the
>>>>>>> Global Object is the window object (despite the fact that it has
>>>>>>> been observed to be in many browsers), ideally some of those
>>>>>>> references should have been written:-
>>>>>>>
>>>>>>> (global.window || global)
>>>>>> Ouch.
>>>>> And what do we consider to be painful about that?
You snipped my
>>>>> disclaimer.
>>>> Your disclaimer is nonsense.
>>> Is it? ISTM that if you declare a global - window - variable, you are
>>> going to screw it up. No?
>>
>> AFAIR, nobody suggested doing that. (And yes, you are going to screw up
>> in the environments we know about. But this is about unknown
>> environments, is it not?)
>
> It is about writing a script that will work in non-browsers, as well as
> browsers.
AISB, there can be no such script if it employs proprietary features.
Indeed, it is questionable whether there can ever be such a script written
in an ECMAScript implementation even if it only employs specified features
as what is specified does not need exactly be what is implemented,
conforming implementations can be of different Editions of ECMAScript, and
implementations have bugs with regard to the Edition they supposedly
implement, too.
> And yes, the OP did suggest declaring a global - window -
> variable and "calling it a day".
Granted, he did; however, I did not, and your suggestion is not any better
than his.
>> The other part is, of course, your readily jumping to conclusions here.
>>
>> First of all, you should rest assured you do not know *anything* about
>> unknown environments (else they would not be unknown, would they?), so
>> all your talk about "properties that are known to be specific to the
>> window object in browsers" does not make any sense in that context.
>
> Of course it does. If we are dealing with a global - window - property,
> then we are dealing with something that is at least trying to look like
> a browser (and likely is a browser).
No.
>> It is really
>> apples and oranges. Whereas you have not even tried to address the
>> question which browsers you are actually talking about here.
>
> All browsers. They've all got windows.
No.
>> Keep in mind
>> that we are talking about a host object here, so it can have (and
>> evidently has) different properties in different browsers, including
>> those that you do not yet know.
>
> Yes, as mentioned, I didn't include any feature detection in the example.
Feature detection cannot remedy the intrinsic problem of this approach.
>> Then, if you assume that the two expressions refer to different objects
>> instead of the same (else you would not need the OR operation in the
>> first place), where did the global object of the other environment
>> suddenly get the magic alert() method from?
>
> Same place that non-browsers get the "magic" setTimeout and setInterval
> methods.
Nonsense.
>> And that aside, why would you even expect such a method to work the same
>> as the method defined for Window instances from a completely different
>> runtime environment to begin with -- because the property has the same
>> name?
>
> A global alert method? I would certainly think it would - at the very
> least - display a text message in some way.
>
>> What does, for example, the implementor of an ECMAScript implementation
>> for an e-book reader need to care what your favorite Web browser
>> implements, and how it does that?
>
> If they define a global alert method, I think its purpose can be
> inferred.
You are mistaken (in both assumptions).
>> Suppose, just suppose, it would work remotely the same
>> as in that Web browser (i.e. it displayed a message to the user, and
>> would not, e.g. log it to a file in the reader's filesystem -- or the
>> book server's? -- instead):
>
> That would be perfectly appropriate for an alert on the server.
And you do not find that ambiguity of your code a little bit disturbing?
>> All things considered it could require, for example,
>> a second argument to indicate the message title, a third for the message
>> type aso., and throw a TypeError when those are missing (or
>> `undefined').
>
> It could, but that would be foolish on the part of the implementors.
No, it would not; how did you get that crazy idea after all, considering
| It isn't up to a random environment to solve issues specific to your
| script.

-- David Mark in <news:hlqbqi$l95$>
?
The implementation needs to satisfy the capabilities of the runtime
environment in which it is used; not the capabilities of some other
environment in which it is not used, only because some people jump to
conclusions about the availability of certain features.
>> Or the order of expected arguments could be reversed or interchanged.
>
> That's even more foolish (and less likely). They'd be asking for
> trouble (and who wants trouble?)
Nonsense.
>> Or it could take no arguments at all.
>
> That would make the least amount of sense for an - alert - method.
No, there could be general behavior that does not need an argument.
>> Or it could only be called under certain circumstances. Or ... And
>> then -- what?
>
> You are reaching.
No, you are. Browsers have nothing to do with non-browsers. That much is
self-evident.
>>>>> So what's your line?
>>>> Don't.
>>> I meant your line of _code_ for calling alert (or setTimeout or
>>> whatever) in an environment-agnostic fashion.
>> As you can hopefully see by now, there can be no such thing.
>
> There are no guarantees with this stuff. There never have been, even in
> browsers. You have to know your history, use sound feature detection
> and still things can go wrong.
Non sequitur. It is foolish to assume that things would work the same
everywhere.
>> The very definition of "proprietary" precludes any reasonable
>> assumptions about the availability or functionality of such features
>> in runtime environments with ECMAScript binding that one knows nothing
>> about.
>
> You can say the same thing about _browser_ host objects, yet viable
> cross-browser scripts are written every day (and have been for a decade).
Yes, cross-*browser*, limited to known implementations in browsers,
sometimes even only a set of known browsers. Implementations based on a
common history of environments and implementations, where some generally
useful proprietary features became de facto standards *for browsers*, and
by that some even became standards that are independent of the runtime
environment or the used programming language.
IOW, it is not reasonable to assume that `if (x) ;' would break in code
written in a ECMAScript implementation in a non-browser when it worked in a
browser ECMAScript implementation in a browser. But it is very reasonable
to assume that `alert(...)' would either break or do something different
than in a browser, in a non-browser environment. It is therefore not
reasonable to insist that working scripts could be written to call such a
method independently of the runtime environment.
PointedEars
--
var bugRiddenCrashPronePieceOfJunk = (
navigator.userAgent.indexOf('MSIE 5') != -1
&& navigator.userAgent.indexOf('Mac') != -1
) // Plone, register_function.js:16