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

Scope with Variables

Guide ,
Apr 23, 2009 Apr 23, 2009

Copy link to clipboard

Copied

Just a very basic question I have NOT yet managed to get through all of the stuff contained in the manuals but does JavaScript have such a thing? Im eager to start trying to convert some of my AppleScripts to JavaScript as a learning exercise and have not come across anything yet. Also while Im here is the "_" underscore special to Extend Script? I've used this character in function names when using AppleScripts do JavaScript without issue but Extend Script marks it red as if it no like it. TVM

TOPICS
Actions and scripting

Views

1.1K

Translate

Translate

Report

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

correct answers 1 Correct answer

Valorous Hero , Apr 23, 2009 Apr 23, 2009

As far as I know the underscrore is a valid character and should have no problem in a function name Mark. I have given it a test in various positions within and prefixing with no problems.

Votes

Translate

Translate
Adobe
Valorous Hero ,
Apr 23, 2009 Apr 23, 2009

Copy link to clipboard

Copied

As far as I know the underscrore is a valid character and should have no problem in a function name Mark. I have given it a test in various positions within and prefixing with no problems.

Votes

Translate

Translate

Report

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
Advisor ,
Apr 23, 2009 Apr 23, 2009

Copy link to clipboard

Copied

You can also use _ as a variable name or function name by itself.

var _ = 20;

function _() {

  return '';

}

Votes

Translate

Translate

Report

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
Guide ,
Apr 23, 2009 Apr 23, 2009

Copy link to clipboard

Copied

I posted too soon and had made my first mistake already Doh! What I had actually done now that I've Rechecked is First keyed an Underscore (as you say this is OK) but this is not visible in my Extend Script although it is there if I C&P to Text Edit. So I thought I have keyed it wrong and what I then did was is an em-dash (option+dash) always mixing these up this is what was marked red and stopped the script running.

As for scope are variables all just script wide if you know what I mean in AppleScript I can have "Property", "Global" & "Variable" the later declared inside of a function is local to the function?

Im making some progress all be it slow… Thank you both

Votes

Translate

Translate

Report

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
Advisor ,
Apr 23, 2009 Apr 23, 2009

Copy link to clipboard

Copied

LATEST

As for scope are variables all just script wide if you know what I mean in AppleScript I can have "Property", "Global" & "Variable" the later declared inside of a function is local to the function?

Get the Flanagan JS book. It will explain this stuff in detail. The

simplified version is that there are two scopes: global and function level.

In this example, the first x is global and the second is local to the

function y. The third x is the same variable as the second even though

it's another declaration.

This is different that what happens in other C-based languages and still

trips me up on occasion.

var x = 10;

function y() {

var x = 20;

if (true) {

var x = 30;

}

};

Votes

Translate

Translate

Report

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