如何从客户端中调用Google App脚本中的类方法?
如何从客户端中调用Google App脚本中的类方法? //客户端
function myClientSideFun() {
google.script.run.withSuccessHandler(onSuccess).myClass.myClassMethod()
function onSucces(msg) { console.log(msg) }
}
//server side
class MyClass {
myClassMethod() { return "myMsg" }
}
let myClass = new MyClass()
How to invoke a class method in google app script from client side ?
//client side
function myClientSideFun() {
google.script.run.withSuccessHandler(onSuccess).myClass.myClassMethod()
function onSucces(msg) { console.log(msg) }
}
//server side
class MyClass {
myClassMethod() { return "myMsg" }
}
let myClass = new MyClass()
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
更多
发布评论
评论(3)
除非将类方法导出不同的顶级功能,否则不可能直接从客户端调用类方法。类只是现有物体周围的句法糖。 私人功能清楚地说,
obj.objectMethod()
无法从客户端起诉。Unless you export the class method in a different top level function, it is not possible to directly call class methods from the client. Classes are just syntactic sugars around existing objects. The documentation on Private functions clearly says that
obj.objectMethod()
isn't callable from the client.非常感谢您的示例和答案,基于我看来我正在弄清楚如何将函数封装在服务器端 - 实际上是用对象字面的:从客户
端呼叫:从客户端呼叫 /1方式:还创建一个“对象”在客户端脚本中并致电../:
Many thanks for the example and for the answer, based on that it seems I am figuring out another way how could I encapsulate functions on server side - actually with an object literal:
Calling from client side /1 way: also create an "object" in client script and call ../:
作为使用对象方法的简单示例。
html_test
code.gs
选项2
以 @bede指出的内容构建有很多使用服务器端对象的方法。
html_test
code.gs
As a simple example of using an object method.
HTML_Test
Code.gs
Options 2
To build on what @Bede noted there are many ways to use server side objects.
HTML_Test
Code.gs