Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

this vs. var

Explorer ,
Oct 07, 2020 Oct 07, 2020

I've been reading that using 'this' instead of 'var', when declaring variables is a better method. Is there a substantive difference?

TOPICS
Create PDFs , PDF forms
1.2K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
1 ACCEPTED SOLUTION
LEGEND ,
Oct 07, 2020 Oct 07, 2020

Declaring a variable using the let keyword allows for a variable to have block level scope, which is generally a good thing. The main problem with using it in PDF is related to backwards compatibility with older verisons of Acrobat/Reader, and other PDF viewers that jave some support for JavaScript, but don't support let..

View solution in original post

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 07, 2020 Oct 07, 2020

The keyword this refers to the current object. The current object is often the document that includes the script, but it also could not be. The keyword var is used to declare a variable. They are not close to being equivalent.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 07, 2020 Oct 07, 2020

I'm not sure what you've been reading but the two are completely different things. To get an idea of how Acrobat JavaScript actually works, you might want to read this article http://khkonsulting.com/2017/01/learning-to-program-javascript-for-adobe-acrobat/

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Oct 07, 2020 Oct 07, 2020

Crimany, I'm very sorry, it was 'let', not 'this'. I got mixed up there... Yes, that question made no sense... I wish I could change that title...

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 07, 2020 Oct 07, 2020

Declaring a variable using the let keyword allows for a variable to have block level scope, which is generally a good thing. The main problem with using it in PDF is related to backwards compatibility with older verisons of Acrobat/Reader, and other PDF viewers that jave some support for JavaScript, but don't support let..

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Oct 07, 2020 Oct 07, 2020

Thank you. It's hard to find decent material on JS for Acrobat...

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 08, 2020 Oct 08, 2020
LATEST

Now that question makes sense. The JS interpreter in Acrobat isn't at the same level as the browsers. There are a lot of key words and common object methods that are not supported.

 

Stick with "var"

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines