application's methods vs. a class in a property's

Hi

I ask questions frequently now, but I do try my best to search for the answers first. This forum really seams great! Very helpful people here!

I could use clarification on one thing. In different threads where people want to call methods from different NS-classes in applescript there seem to be at least two ways to do this. One way I have seen is this

set myString to current application's NSString's stringWithString_("Eat my shorts")

The current applications is called where apparently a reference to the NSString class exist.

Another method I seen is when a property containing a reference to a NS-class is stored before the “script-command” which later is used to call a method. Like this

property NSMutableArray : class "NSMutableArray"

script MyTestAppDelegate

on myHandler()
set myArray to NSMutableArray's alloc()'s init()
end myHandler

end script

I´m curious to what differs between the two techniques and when to use which? If there´s no difference, is there a kind of “best practice”?

There is no difference. You can use either, but if you declare a property for the class name, then if you share snippets of code or you reuse code in other apps, the code won’t work, unless you declare the property in the new context as well. So, if you are posting code, or otherwise sharing, I would stick with the “current application’s” way. The only time I use the property method, is if I need to use the same class numerous times.

Ric

Good to know! I too felt that the “application’s”-approach seems more tidy code-wise… cheers!