Skip to main content
Sumit_KGL
Inspiring
March 23, 2021
Answered

Could you please check what is the difference between both the snippet?

  • March 23, 2021
  • 1 reply
  • 425 views

Dear Member,

 

Could you please check what is the difference between both the snippet? 

First one is giving wrong output.

 

Sumit

 

                parentPage = (prevPageItem && prevPageItem.parentPage.documentOffset >= element.getParentPage().documentOffset) ?
                    prevPageItem.parentPage :
                    (element.getParentPage().documentOffset > firstPage.documentOffset) ?
                        element.getParentPage() :
                        document.pages.item(parentPage.documentOffset + 1);

 

parentPage = (function () {
                    if (prevPageItem && prevPageItem.parentPage.documentOffset >= element.getParentPage().documentOffset)
                        return prevPageItem.parentPage;
                    else if ((elementParentPage = element.getParentPage()).documentOffset > firstPage.documentOffset)
                        return elementParentPage;
                    else return document.pages.item(firstPage.documentOffset + 1);
                }).call();

VS 

This topic has been closed for replies.
Correct answer BarlaeDC

Hi,

I am not sure what is different but I would guide against using nested ternary methods as this makes the code harder to follow, therefore I would always recommend that you use the second option, in terms of coding style.

 

1 reply

BarlaeDC
Community Expert
BarlaeDCCommunity ExpertCorrect answer
Community Expert
March 23, 2021

Hi,

I am not sure what is different but I would guide against using nested ternary methods as this makes the code harder to follow, therefore I would always recommend that you use the second option, in terms of coding style.

 

Sumit_KGL
Sumit_KGLAuthor
Inspiring
March 24, 2021

Thank you BarlaeDC.