Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #32867
| From | tony@mountifield.org (Tony Mountifield) |
|---|---|
| Newsgroups | comp.lang.javascript |
| Subject | Re: Understanding someone's code |
| Date | 2017-03-30 11:43 +0000 |
| Organization | Software Insight Ltd., Winchester, UK |
| Message-ID | <obir0r$p3e$1@softins.softins.co.uk> (permalink) |
| References | <WumdnYlb48xrFUHFnZ2dnUU7-K_NnZ2d@westnet.com.au> <34qdnaF51IrJJUHFnZ2dnUU7-WednZ2d@westnet.com.au> <XnsA7487B53461A9eejj99@194.109.6.166> |
In article <XnsA7487B53461A9eejj99@194.109.6.166>,
Evertjan. <exxjxw.hannivoort@inter.nl.net> wrote:
> Andrew Poulos <ap_prog@hotmail.com> wrote on 30 Mar 2017 in
> comp.lang.javascript:
>
> > On 30/03/2017 3:26 PM, Andrew Poulos wrote:
> >> I'm looking through some code I found online and one bit has this
> >>
> >> function k() {
> >> var a;
> >> if (b.onScroll) b.onScroll();
> >> b.getPageInView && (a = b.getPageInView()) && (F = a,
> >> document.getElementById("pageNumber").value = a);
> >> }
> >>
> >> which has me confused. Is the line
> >>
> >> b.getPageInView && (a = b.getPageInView()) && (F = a,
> >> document.getElementById("pageNumber").value = a);
> >>
> >> equivalent to
> >>
> >> if (b.getPageInView) {
> >> a = b.getPageInView();
> >> F = a;
> >> document.getElementById("pageNumber").value = a;
> >> }
> >
> > Or should I have said, is equivalent to
> >
> > if (b.getPageInView) {
> > a = b.getPageInView();
> > if (a) {
> > F = a;
> > document.getElementById("pageNumber").value = a;
> > }
> >}
>
> No.
Why not? It looks equivalent to me, in that specific case. If you believe
it to be a wrong interpretation of the original code, why not provide
a better one, instead of the unrelated and simple example below?
> The right side of && is only executed
> if and after[!] execution of the left side has returned true.
Yes, that's right. Which is what the OP's "if" statements are doing.
Remember that in the original code, the result of the X && Y && Z
expression is discarded, not assigned.
> So:
>
> 'use strict'
> let a = 4;
> document.write( a ); // 4
> document.write( a && 15-15 ); // 0
> document.write( a ); // 4
> document.write( (a=0) && (a=1) ); // 0
> document.write( a ); // 0
> document.write( (a=17) && (a=0) && (a=13) ); // 0
> document.write( a ); // 0
All true, but not relevant to the original example.
Cheers
Tony
--
Tony Mountifield
Work: tony@softins.co.uk - http://www.softins.co.uk
Play: tony@mountifield.org - http://tony.mountifield.org
Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Understanding someone's code Andrew Poulos <ap_prog@hotmail.com> - 2017-03-30 15:26 +1100
Re: Understanding someone's code Andrew Poulos <ap_prog@hotmail.com> - 2017-03-30 18:48 +1100
Re: Understanding someone's code "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2017-03-30 12:07 +0200
Re: Understanding someone's code tony@mountifield.org (Tony Mountifield) - 2017-03-30 11:43 +0000
Re: Understanding someone's code "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2017-03-30 14:00 +0200
Re: Understanding someone's code tony@mountifield.org (Tony Mountifield) - 2017-03-30 13:44 +0000
Re: Understanding someone's code "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2017-03-30 19:07 +0200
Re: Understanding someone's code JJ <jj4public@vfemail.net> - 2017-03-30 18:58 +0700
Re: Understanding someone's code Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2017-03-30 18:13 +0200
Re: Understanding someone's code Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2017-03-30 18:13 +0200
Re: Understanding someone's code John G Harris <niam@jghnorth.org.uk.invalid> - 2017-03-31 10:30 +0100
Re: Understanding someone's code Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2017-04-02 14:41 +0200
Re: Understanding someone's code John G Harris <niam@jghnorth.org.uk.invalid> - 2017-04-02 19:05 +0100
Re: Understanding someone's code Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2017-04-10 05:00 +0200
Re: Understanding someone's code John G Harris <niam@jghnorth.org.uk.invalid> - 2017-04-10 10:03 +0100
csiph-web