Can I use class in the custom module and construct...
# suitescript
n
Can I use class in the custom module and constructor? It seems to be throwing the error.
s
you should be able to in SS2.1
n
That's what I thought too but it throwing an error on the constructor..
w
could be a syntax error. does the following work ok?
Copy code
class mycustomclass{
    constructor(variable)
    {
        this.variable = variable
    }
    report()
    {
        log.debug({
            title: "report",
            details: this.variable
        })
    }
}
let instance = new mycustomclass('hello');
instance.report()
s
if you're using typescript, syntax errors aren't really a thing
I can confirm that I'm using classes quite successfully in SS2.1
• however at quick glance at one class shows I'm not defining a constructor
n
I am not using TS.
@Webber I have made a change. Probably a syntax issue. Trying now.
Worked now..
I was defining the fields after the class.
Copy code
class SEARCH {
this.fld1;
this.fld2

}
This was causing the problem.
Thank you @stalbert @Webber
s
Typescript would have given you a clear error on that code and saved you whatever time you spent before asking here, plus the time spent here on this forum. 🙂
n
Your efforts to drive me towards TypeScript are working 😄
s
heh, just pointing out some TS benefits. I do admit I occasionally have to spend some time getting my 'types' right where I wouldn't have to in plain JS, but the end result is more solid code, so I think the tradeoff is well worth it so far.
👍 1
n
private fields/methods will work fine in SS2.1, right?
s
private as in hashed (#)? I don't know - haven't tried but I think that's newer than ES2019 which is what I heard SS2.1 supports. Worth a try - let us know if it works
n
# does not work in NS.
s
bummer, but not surprising. Perhaps when the update to ES2020 or whatnot?
n
But I assumed that everything JS should now be supported. Well...anyway.
s
JS changes are 'standardized' individually now, so it's difficult to know exactly which features are or are not supported by a given runtime unless an exhaustive list is made available.