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
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.
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.
Copy link to clipboard
Copied
You can also use _ as a variable name or function name by itself.
var _ = 20;
function _() {
return '';
}
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
Copy link to clipboard
Copied
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;
}
};