在 GAS 中,'instanceof' 如何用于 Spreadsheet?

In GAS, how can ‘instanceof’ be used for Spreadsheet?

我想看看一个变量是否是 Spreadsheet 的一个实例。

示例,

function foo(hoge){
  let name;
  if (hoge isinstanceof SpreadsheetApp.Spreadsheet){
      name = hoge.getName()
  }else {
      name = hoge;
  }
}

但是我好像不能像上面那样做。我应该将“SpreadsheetApp.Spreadsheet”更改为什么?

也许是这样的:

function test101() {
  const ss = SpreadsheetApp.getActive();
  if(ss instanceof Object && ss.hasOwnProperty('toast')) {
     Logger.log('Then it is a spreadsheet');
  }
}

instanceof

type of

hasOwnProperty