I have been experimenting with creating more object oriented scripts (because I have a lot of them and plan to have more). I have a string “class”, a file “class”, etc, each with its own set of “properties” (global variables) and “methods” (subroutines). I have read that I can create multiple “instances” by loading the script multiple times, assigning it to a different variable each time:
global strObjectA
set strObjectA to load script file filePath
global strObjectB
set strObjectB to load script file filePath
I’ve also read that this is a bad idea, although the person who said so didn’t say why. Is it a bad idea (especially given the growing number of subroutines in my string class)? Also, is it okay to load a script within itself? For example, would it be bad to do this within my string class?
global Str_source
set Str_source to {"a ", "list of ", " Items to trim"}
on trim(theseCharacters)
if class of Str_source is list then
repeat with i from 1 to (count of Str_source)
set thisStr to load script file pathToThisFileWeAreInRightNow
set item i of Str_source to thisStr's trim_in_string(theseCharacters)
end repeat
end if
end trim