小编M. *_*nje的帖子

在Google Apps脚本库中创建类似命名空间的组织

我正在研究使用谷歌应用程序脚本构建工具集.这个问题是,据我所知,只允许一个级别的组织.您可以创建一个名为Stopwatch的库,并调用方法Stopwatch.start()和Stopwatch.stop(),这非常酷.

我的想法虽然更像是Utils.Stopwatch().start()和Utils.Timer.start()等.我认为它在javascript中肯定是可能的,但为了不断破坏Apps Script自动完成功能,它需要以某种格式添加.下面是一个例子,它做错了(给出错误),但也许节省了一些时间.它基于这篇文章.

/**
* A stopwatch object.
* @return {Object} The stopwatch methods
*/
function Stopwatch() 
{
  var current;

  /**
  * Stop the stopwatch.
  * @param {Time} time in miliseconds
  */
  function timeInSeconds_(time)
  {
    return time/1000;
  }

  return 
    {
      /**
      * Start the stopwatch.
      */
      start: function() 
      {
        var time = new Date().getTime();
        current = timeInSeconds_(time);
      },

      /**
      * Stop the stopwatch.
      * @return {decimal} time passed since calling 
      *    start (in seconds)
      */
      stop: function() 
      { …
Run Code Online (Sandbox Code Playgroud)

namespaces jsdoc google-apps-script

8
推荐指数
1
解决办法
2261
查看次数

标签 统计

google-apps-script ×1

jsdoc ×1

namespaces ×1