guest-book-as
guest-book-as copied to clipboard
Revisit constructor in model that is likely unnecessary
At the time of this writing, here's the latest commit where we have: https://github.com/near-examples/guest-book/blob/0676d825b79be48ab7a00004ed055be09a42895d/assembly/model.ts#L10
constructor(public text: string) {
this.premium = context.attachedDeposit >= u128.from('10000000000000000000000');
this.sender = context.sender;
}
Not sure what the point of text
is here, but I haven't been in the AS world for a while.
I'm rather new to AssemblyScript too but it looks like constructors support shorthand instance property assignment. Essentially the public
keyword means instances will have a property called "text" with a type of string
. Without the public
keyword, the parameter will be private so the constructor will have the flexibility to do whatever it wants with it.
In the TypeScript world (given it's more closely related syntactically than standard JavaScript), it's the equivalent to writing:
constructor(text: string) {
this.text = text;
this.premium = context.attachedDeposit >= u128.from('10000000000000000000000');
this.sender = context.sender;
}
TLDR: Removing this parameter will mean messages won't have any contents other than the metadata (i.e. who sent it and whether a donation was attached).