Hi there I’ve been wondering whether Sublibraries and/or classes in libraries are possible to implement in JXA. Here’s 2 ways I would imagine such a library working, but neither implementations work (errors included in comments):
Implementation 1 requires 3 files:
SFLib.scpt: {
SFPrefs = Library('SFPrefs')
}
SFPrefs.scpt: {
this.bar = "hello world"
this.foo = function(){
this.bar = "hello foo"
}
}
test.scpt: {
SFLib = Library('SFLib')
SFLib.SFPrefs.bar //ERROR [TypeError: Objective-C blocks called as constructors must return an object.]
SFLib.SFPrefs.foo //ERROR [TypeError: Undefined is not a function. (evaluating 'SFPrefs.foo')]
}
Implementation 2 requires 2 files:
SFLib.scpt: {
SFPrefs = function(){
this.bar = "hello world"
this.foo = function(){
this.bar = "hello foo"
}
}
}
Test.scpt: {
SFLib = Library('SFLib')
SFPrefs = new SFLib.SFPrefs()
SFPrefs.bar //ERROR [TypeError: Objective-C blocks called as constructors must return an object.]
SFPrefs.foo() //ERROR [TypeError: Object is not a function. (evaluating 'SFPrefs.foo()')]
}
If anyone can shed any light on this topic, that’d be great!