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

M. *_*nje 8 namespaces jsdoc google-apps-script

我正在研究使用谷歌应用程序脚本构建工具集.这个问题是,据我所知,只允许一个级别的组织.您可以创建一个名为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() 
      {
        var time = new Date().getTime();
        var difference = timeInSeconds_(time) - this.current;
        return difference.toFixed(3);
      }
    };
}
Run Code Online (Sandbox Code Playgroud)

谢谢

edd*_*son 3

您可以在此处提交功能请求:

http://code.google.com/p/google-apps-script-issues/issues/list

  • 我创建了错误报告 http://code.google.com/p/google-apps-script-issues/issues/detail?id=1389&thanks=1389&ts=1338940848 (6认同)