I have a question.
In the formal web page of google.script run, they saids that you can call "any server-side function" from client side using google.script.run.
In the below gs file, I defined function "hoge" using normal function expression.(the "this!" row)
If I execute this situation, output is randomly 1-4 numbers displayed on browser
By the way, I tried to change the define style of function "hoge". I created 3 pattern using anonymous function. (all are called from client side using "hoge(vv)")
var hoge = function hoge(x){return x;};
(both side using "hoge" keyword) → then this worked same as normal function definition style.var hoge = function (x){return x;};
(only left using "hoge" keyword) → errorvar hogeNot = function hoge(x){return x;};
(only right using "hoge" keyword) → error
Q. Why, "1" work well, but "2" is error.
Thank you.
// gs file
var x;
function doGet() {
return HtmlService.createTemplateFromFile("hello").evaluate(); // テンプレートオブジェクトの取得
}
function hoge(x){ // this!
return x;
}
// html file
<!DOCTYPE html>
<html>
<head>
<base target="_top">
</head>
<body>
<p id="wi">hello</p>
<script>
function success(get){
document.getElementById("wi").insertAdjacentHTML("afterend","<p>" + get + "</p>");
}
for (var v=1; v <= 4; ++v){ // aaを4回呼ぶ
aa(v);
}
async function aa(vv){
await google.script.run.withSuccessHandler(success).hoge(vv);
}
</script>
</body>
</html>