Path: csiph.com!news.mixmin.net!news.albasani.net!.POSTED!softins.co.uk!not-for-mail From: tony@mountifield.org (Tony Mountifield) Newsgroups: comp.lang.javascript Subject: Re: Understanding someone's code Date: Thu, 30 Mar 2017 13:44:32 +0000 (UTC) Organization: Software Insight Ltd., Winchester, UK Lines: 99 Message-ID: References: X-Trace: news.albasani.net gWaH+2Ece5UBk49jBH0aj20obJWFZ3PLVtzPAPQaXjHiFsYbDZKb7bN3Q6rO71iBQAw0QjBUVpjx9tjaIKFzeg== NNTP-Posting-Date: Thu, 30 Mar 2017 13:45:21 +0000 (UTC) Injection-Info: news.albasani.net; logging-data="/o+BBlKMyoDlCnke76/a+2jDi+GrJGU8FOJFOKBHlzlkl0a8Yp5xk9gdcMmaHMbULEccHGrT2hHdxTTCQtaUk2KhxRXImBRvU4LmtIfbu9VQfOh7tpOUSUMlisz/i9x/"; mail-complaints-to="abuse@albasani.net" Originator: tony@softins.co.uk () X-Newsreader: trn 4.0-test77 (Sep 1, 2010) Cancel-Lock: sha1:EdRigoXGalzXRLw9ONSLSv+33TM= Xref: csiph.com comp.lang.javascript:32878 In article , Evertjan. wrote: > tony@mountifield.org (Tony Mountifield) wrote on 30 Mar 2017 in > comp.lang.javascript: > (original statement re-added for comparison) > >> b.getPageInView && (a = b.getPageInView()) && (F = a, > >> document.getElementById("pageNumber").value = a); > >> > 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. > > Incorrect, did you test it? It was simple enough to understand by inspection. > After: > > F = 7; > a = 0; > if (a) { > F = a; > document.getElementById("pageNumber").value = a; > } > > F will be 7, > > while after: > > F = 7; > a = 0; > F = (F = a) && (document.getElementById("pageNumber").value = a); > > F will be 0; What's an initial assignment to F got to do with it? That wasn't in the original example. Nor was your outer assignment to F in the third line. Let's consider the original code piece by piece: b.getPageInView && (a = b.getPageInView()) && (F = a, document.getElementById("pageNumber").value = a); 1. Evaluate b.getPageInView. If false, do nothing further due to short- circuit evaluation, and discard its value, since it is not assigned. 2. Invoke b.getPageInView() and assign its value to a. If the assigned value was false, do nothing further. 3. Assign the value of a to F. 4. Assign the value of a to document.getElementById("pageNumber").value You will find exactly the same steps describe the OP's interpretation: if (b.getPageInView) { a = b.getPageInView(); if (a) { F = a; document.getElementById("pageNumber").value = a; } } > > If you believe > > it to be a wrong interpretation of the original code, why not provide > > a better one > > This is not a church, > faith does not come into coding, > faith being nonsense anyway. s/believe/consider/ or s/believe/think/. I was using "believe" in one of those meanings, nothing to do with faith. Sounds like you have an axe to grind regarding the latter. > > , instead of the unrelated and simple example below? > > I try to teach to the best of my knowledge, > not take over the coding, > this NG not being a helpdesk. That's true, it isn't. But if you volunteer to respond, it doesn't help if you don't answer the question asked. Cheers Tony -- Tony Mountifield Work: tony@softins.co.uk - http://www.softins.co.uk Play: tony@mountifield.org - http://tony.mountifield.org