Javascript、GASとも構造体はないけど、クラスかオブジェクトを使えば構造体っぽくできるようです。
以下に参考のURLを記載します。他にもあると思います。
・GASのクラス
https://tonari-it.com/gas-class-object-property-method/#toc5
・JAVASCRIPTの構造体もどき
https://techacademy.jp/magazine/18488
1 2 3 4 5 |
function User(id, name, point){ this.id = id; this.name = name; this.point = point; } |
実際にやってみた
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <title>JS構造体もどき</title> <script> //構造体のように使ってみた function User(id, name, point){ this.id = id; this.name = name; this.point = point; } </script> </head> <body> ここに名前が表示される<br> <div id="output"></div> <script type="text/javascript"> //scriptの位置に注意する。id=outputが下の方だとエラーになる var tag_element = document.getElementById("output"); var test01 = new User(1,"taro",20); tag_element.innerHTML = test01.name; </script> </body> </html> |
https://qiita.com/tawatawa/items/f36b7f82e3eddf8cbd44
https://www.ipentec.com/document/javascript-object-definition
https://www.yunabe.jp/docs/javascript_class_in_google.html
>>いろいろな定義があるのでJAVASCRIPTのコードの参考になる
・JAVASCRIPTのクラス
https://www.sejuku.net/blog/49551#JavaScript
1 2 3 4 5 6 7 8 9 10 11 |
class User { constructor( name, age) { this.name = name; this.age = age; } getName() { return this.name; } } |