[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.javascript

null variable issue???

helixpoint

5/20/2016 11:46:00 AM

This is the line. Can't I use...&& to stop this from returning null

return (E.Util.ieVersion() < 9 ? a.caller : a.caller.caller);

I know this is wrong, but something like....

return (E.Util.ieVersion() < 9 ? &&a.caller : &&a.caller.caller);
10 Answers

Michael Haufe (\"TNO\")

5/20/2016 12:21:00 PM

0

On Friday, May 20, 2016 at 6:45:35 AM UTC-5, helix...@gmail.com wrote:
> This is the line. Can't I use...&& to stop this from returning null
>
> return (E.Util.ieVersion() < 9 ? a.caller : a.caller.caller);
>
> I know this is wrong, but something like....
>
> return (E.Util.ieVersion() < 9 ? &&a.caller : &&a.caller.caller);

You have to be certain that everything you are dispatching on is not null

Also, You should not be writing code targeting a specific browser. Browsers lie. Finally, there is no reason to use caller. Refactor your code

helixpoint

5/20/2016 12:42:00 PM

0

On Friday, May 20, 2016 at 7:45:35 AM UTC-4, helix...@gmail.com wrote:
> This is the line. Can't I use...&& to stop this from returning null
>
> return (E.Util.ieVersion() < 9 ? a.caller : a.caller.caller);
>
> I know this is wrong, but something like....
>
> return (E.Util.ieVersion() < 9 ? &&a.caller : &&a.caller.caller);

Both are returning null. How do I return false if both are null

Michael Haufe (\"TNO\")

5/20/2016 1:05:00 PM

0

On Friday, May 20, 2016 at 7:42:34 AM UTC-5, helix...@gmail.com wrote:
> On Friday, May 20, 2016 at 7:45:35 AM UTC-4, helix...@gmail.com wrote:
> > This is the line. Can't I use...&& to stop this from returning null
> >
> > return (E.Util.ieVersion() < 9 ? a.caller : a.caller.caller);
> >
> > I know this is wrong, but something like....
> >
> > return (E.Util.ieVersion() < 9 ? &&a.caller : &&a.caller.caller);
>
> Both are returning null. How do I return false if both are null

both of what? have you identified which object is returning null? I'm assuming caller (which you shouldn't be using anyway).

null instanceof Object === false

as does

null || false

Ben Bacarisse

5/20/2016 1:11:00 PM

0

helixpoint@gmail.com writes:

> On Friday, May 20, 2016 at 7:45:35 AM UTC-4, helix...@gmail.com wrote:
>> This is the line. Can't I use...&& to stop this from returning null
>>
>> return (E.Util.ieVersion() < 9 ? a.caller : a.caller.caller);
>>
>> I know this is wrong, but something like....
>>
>> return (E.Util.ieVersion() < 9 ? &&a.caller : &&a.caller.caller);

What's the && about? That looks like a syntax error.

> Both are returning null. How do I return false if both are null

You probably think that's clear, but it's not. To what two things does
"both" refer?

But I will repeat the advice you've had: test for browser versions, and
using "caller" are both signs that something is amiss elsewhere.

--
Ben.

helixpoint

5/20/2016 1:30:00 PM

0

On Friday, May 20, 2016 at 7:45:35 AM UTC-4, helix...@gmail.com wrote:
> This is the line. Can't I use...&& to stop this from returning null
>
> return (E.Util.ieVersion() < 9 ? a.caller : a.caller.caller);
>
> I know this is wrong, but something like....
>
> return (E.Util.ieVersion() < 9 ? &&a.caller : &&a.caller.caller);

If both object are null in the ternary, I get an error because it is looking for a true or false returned. If it is null, I need to return true

JJ

5/20/2016 1:46:00 PM

0

On Fri, 20 May 2016 04:45:30 -0700 (PDT), helixpoint@gmail.com wrote:
> This is the line. Can't I use...&& to stop this from returning null
>
> return (E.Util.ieVersion() < 9 ? a.caller : a.caller.caller);
>
> I know this is wrong, but something like....
>
> return (E.Util.ieVersion() < 9 ? &&a.caller : &&a.caller.caller);

"E.Util.ieVersion()" returns any number depending on the browser version.
"a.caller" is null if "a" is an event handler.
"a.caller.caller" is null if "a.caller" is an event handler.

JJ

5/20/2016 1:53:00 PM

0

On Fri, 20 May 2016 06:29:57 -0700 (PDT), helixpoint@gmail.com wrote:
> On Friday, May 20, 2016 at 7:45:35 AM UTC-4, helix...@gmail.com wrote:
>> This is the line. Can't I use...&& to stop this from returning null
>>
>> return (E.Util.ieVersion() < 9 ? a.caller : a.caller.caller);
>>
>> I know this is wrong, but something like....
>>
>> return (E.Util.ieVersion() < 9 ? &&a.caller : &&a.caller.caller);
>
> If both object are null in the ternary, I get an error because it is looking for a true or false returned. If it is null, I need to return true

If it needs to return a boolean type based on whether the function caller
are null or non null, use this:

return !!(E.Util.ieVersion() < 9 ? a.caller : a.caller.caller);

JJ

5/20/2016 1:56:00 PM

0

On Fri, 20 May 2016 06:29:57 -0700 (PDT), helixpoint@gmail.com wrote:
> On Friday, May 20, 2016 at 7:45:35 AM UTC-4, helix...@gmail.com wrote:
>> This is the line. Can't I use...&& to stop this from returning null
>>
>> return (E.Util.ieVersion() < 9 ? a.caller : a.caller.caller);
>>
>> I know this is wrong, but something like....
>>
>> return (E.Util.ieVersion() < 9 ? &&a.caller : &&a.caller.caller);
>
> If both object are null in the ternary, I get an error because it is looking for a true or false returned. If it is null, I need to return true

Use this then.

return (E.Util.ieVersion() < 9 ? a.caller : a.caller.caller) || true;

Thomas 'PointedEars' Lahn

5/20/2016 7:07:00 PM

0

JJ wrote:

> On Fri, 20 May 2016 06:29:57 -0700 (PDT), helixpoint@gmail.com wrote:
>> On Friday, May 20, 2016 at 7:45:35 AM UTC-4, helix...@gmail.com wrote:
>>> This is the line. Can't I use...&& to stop this from returning null
>>>
>>> return (E.Util.ieVersion() < 9 ? a.caller : a.caller.caller);
>>>
>>> I know this is wrong, but something like....
>>>
>>> return (E.Util.ieVersion() < 9 ? &&a.caller : &&a.caller.caller);
>>
>> If both object are null in the ternary, I get an error because it is
>> looking for a true or false returned. If it is null, I need to return
>> true
>
> Use this then.
>
> return (E.Util.ieVersion() < 9 ? a.caller : a.caller.caller) || true;

It is a mistake to depend on browser sniffing when there are more reliable
alternatives. The OP is probably having an Xâ??Y problem, attempting to fix
with this a problem that occurred only because of a wrong approach.

--
PointedEars
FAQ: <http://PointedEars.... | SVN: <http://PointedEars.de...
Twitter: @PointedEars2 | ES Matrix: <http://PointedEars.de/es-...
Please do not cc me. / Bitte keine Kopien per E-Mail.

Thomas 'PointedEars' Lahn

5/22/2016 5:24:00 AM

0

Thomas 'PointedEars' Lahn wrote:

> JJ wrote:
>> On Fri, 20 May 2016 06:29:57 -0700 (PDT), helixpoint@gmail.com wrote:
>>> On Friday, May 20, 2016 at 7:45:35 AM UTC-4, helix...@gmail.com wrote:
>>>> This is the line. Can't I use...&& to stop this from returning null
>>>>
>>>> return (E.Util.ieVersion() < 9 ? a.caller : a.caller.caller);
>>>>
>>>> I know this is wrong, but something like....
>>>>
>>>> return (E.Util.ieVersion() < 9 ? &&a.caller : &&a.caller.caller);
>>>
>>> If both object are null in the ternary, I get an error because it is
>>> looking for a true or false returned. If it is null, I need to return
>>> true
>>
>> Use this then.
>>
>> return (E.Util.ieVersion() < 9 ? a.caller : a.caller.caller) || true;
>
> It is a mistake to depend on browser sniffing when there are more reliable
> alternatives. The OP is probably having an Xâ??Y problem, attempting to fix
> with this a problem that occurred only because of a wrong approach.

JFTR:

It appears that V8 has been changed so that the deprecated â??callerâ? property
is now a property of the â??argumentsâ? object even in strict mode, but as
specified for strict mode the direct (not typeof-like) property (read)
access to â??arguments.callerâ? throws an exception.

There had not been a â??callerâ? property in strict mode, so the approach to
avoid the strict mode violation using feature tests was successful.

This caused me to commit the following workaround to the stack trace
generator, jsx.getStackTrace(), today:

-------------------------------------------------------------------------------
diff --git a/object.js b/object.js
index b341e99..a585fa8 100644
--- a/object.js
+++ b/object.js
@@ -2429,34 +2429,8 @@ de.pointedears.jsx = jsx;

var result = '';

- var caller =
- (jsx.object._hasOwnProperty(jsx_getStackTrace, "caller") &&
jsx_getStackTrace.caller)
- || (jsx.object._hasOwnProperty(arguments, "caller") &&
arguments.caller);
-
- if (caller)
+ if (typeof Error == "function")
{
- /* JScript and older JavaScript */
- while (caller != null)
- {
- result += '> ' + (jsx.object.getFunctionName(caller, true) ||
"anonymous")
- + '\n';
- if (caller.caller == caller)
- {
- result += '*';
- break;
- }
-
- caller = caller.caller;
- }
- }
- else
- {
- /* other */
- if (typeof Error != "function")
- {
- return result;
- }
-
var stack = parseErrorStack(new Error());
result = stack.slice(2).join("\n");
// for (var i = 1; i < stack.length; i++)
@@ -2465,6 +2439,35 @@ de.pointedears.jsx = jsx;
// }
}

+ /*
+ * Avoid strict violation; implementations with Error should also have
+ * the â??stackâ? property
+ */
+ /* FIXME: Use local strict mode declaration only */
+ if (!stack)
+ {
+ /* JScript and older JavaScript */
+ var caller =
+ (jsx.object._hasOwnProperty(jsx_getStackTrace, "caller") &&
jsx_getStackTrace.caller)
+ || (jsx.object._hasOwnProperty(arguments, "caller") &&
arguments.caller);
+
+ if (caller)
+ {
+ while (caller != null)
+ {
+ result += '> ' + (jsx.object.getFunctionName(caller, true) ||
"anonymous")
+ + '\n';
+ if (caller.caller == caller)
+ {
+ result += '*';
+ break;
+ }
+
+ caller = caller.caller;
+ }
+ }
+ }
+
return result;
};
-------------------------------------------------------------------------------

It is only a temporary workaround because the problem occured now because I
had made the mistake of declaring strict mode *globally* before. AISB, this
is a bad idea as then all code that is executed after the declaration runs
in strict mode, and it might not be written to that â?? especially if the code
is third-party code.

--
PointedEars
FAQ: <http://PointedEars.... | SVN: <http://PointedEars.de...
Twitter: @PointedEars2 | ES Matrix: <http://PointedEars.de/es-...
Please do not cc me. / Bitte keine Kopien per E-Mail.