如何從客戶端呼叫谷歌應用腳??本中的類方法?//客戶端
function myClientSideFun() {
google.script.run.withSuccessHandler(onSuccess).myClass.myClassMethod()
function onSucces(msg) { console.log(msg) }
}
//服務器端
class MyClass {
myClassMethod() { return "myMsg" }
}
let myClass = new MyClass()
uj5u.com熱心網友回復:
除非您在不同的頂級函式中匯出類方法,否則無法直接從客戶端呼叫類方法。類只是圍繞現有物件的語法糖。Private 函式的檔案清楚地表明obj.objectMethod()它不能從客戶端呼叫。
uj5u.com熱心網友回復:
作為使用物件方法的簡單示例。
HTML_Test
<!DOCTYPE html>
<html>
<head>
<base target="_top">
</head>
<body>
<input id="testParam" type="text">
<script>
(function () {
google.script.run.withSuccessHandler(
function(param) {
document.getElementById("testParam").value = param;
}
).getTestParam();
})();
</script>
</body>
</html>
代碼.gs
class TestObject {
constructor(param) {
this.param = param;
}
get getParam() { return this.param; }
}
var obj = new TestObject("hello");
function getTestParam() {
return obj.getParam;
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/479569.html
下一篇:自定義日期和時間格式
