Javascript对象变量在对象方法中不可用

Javascript对象变量在对象方法中不可用,javascript,javascript-objects,Javascript,Javascript Objects,我正在尝试javascript对象。有趣的是,当我试图在方法内部使用变量时,它告诉我要么它们的变量未定义,要么方法找不到 var oPdf = { hFolderHandle: DocsList.getFolderById('0B1rbQnVtcj5CNWNmekFWMG9DZzA'), hTempHtmlHandle: "", hPdfHandle: "", mToastFeedback: function () { SpreadsheetApp.getActiveS

我正在尝试javascript对象。有趣的是,当我试图在方法内部使用变量时,它告诉我要么它们的变量未定义,要么方法找不到

var oPdf = {
  hFolderHandle: DocsList.getFolderById('0B1rbQnVtcj5CNWNmekFWMG9DZzA'),
  hTempHtmlHandle: "",
  hPdfHandle: "",

  mToastFeedback: function () {
    SpreadsheetApp.getActiveSpreadsheet().toast('Finished');
  }
};
oPdf.hTempHtmlHandle = oPdf.hFolderHandle.createFile('test.html', oInvoice.sInvoiceBody, 'text/html');
oPdf.hPdfHandle = oPdf.hFolderHandle.createFile(oPdf.hTempHtmlHandle.getAs('application/pdf')).rename('test.pdf');
DocsList.getFileById(oPdf.hTempHtmlHandle.getId()).setTrashed(true);
例如,如果我移动行oPdf.hTempHtmlHandle=oPdf.hFolderHandle.createFile'test.html',oInvoice.sInvoiceBody'text/html';转化为一种方法 在oPdf内部,就像这样:

 mTestMethod:function () {
      oPdf.hTempHtmlHandle = oPdf.hFolderHandle.createFile('test.html', oInvoice.sInvoiceBody, 'text/html');
 },
GoogleApps脚本告诉我hFolderHandle不知道createFile的方法

有什么想法吗

好的,这在上面的例子中很好,但在这里它不起作用,我不知道为什么

var oSpreadSheetApp = {
    hSpreadSheet: SpreadsheetApp.getActiveSpreadsheet(), //Retrieving the handle to the currently open spread-sheet
    hInvoiceSheet: this.hSpreadSheet.getSheetByName('Rechnungen')
};
由于方法mTestMethod是oPdf对象的一部分,您可以像访问任何属性或方法一样通过调用此edit:或oPdf来访问它,后者是指向该对象的指针

评论后编辑:

问题是oPdf.hFolderHandle或this.hFolderHandle不知道任何名为createFile的方法

感谢菲利克斯·克林的指点

问题更新后更新

该代码:

var oSpreadSheetApp = {
    hSpreadSheet: SpreadsheetApp.getActiveSpreadsheet(), //Retrieving the handle to the currently open spread-sheet
    hInvoiceSheet: this.hSpreadSheet.getSheetByName('Rechnungen')
};
那么应该是

var oSpreadSheetApp = {
    hSpreadSheet: SpreadsheetApp.getActiveSpreadsheet(), //Retrieving the handle to the currently open spread-sheet
    hInvoiceSheet: SpreadsheetApp.getSheetByName('Rechnungen')
};

因为这里的电子表格应用程序显然不是对象oSpreadSheetApp的一部分。

使用this.hTempHtmlHandle=…请发布一个完整的示例,并说明如何/在何处调用该方法。你绝对是正确的pc射手。。。我现在觉得自己很愚蠢。你想回答这个问题,让我接受吗?我刚刚遇到了另一个不起作用的示例,将编辑问题。在新的示例中,这不是指oSpreadSheetApp,所以它不起作用。在第一个示例中,如果同时为oPdf分配了不同的值,则将代码放入方法中将不起作用。即使这是公认的答案,但应该注意,this.hTempHtmlHandle与oPdf.hTempHtmlHandle没有什么不同。因此,如果这个解决方案有效,那么原始代码也应该有效。
var oSpreadSheetApp = {
    hSpreadSheet: SpreadsheetApp.getActiveSpreadsheet(), //Retrieving the handle to the currently open spread-sheet
    hInvoiceSheet: SpreadsheetApp.getSheetByName('Rechnungen')
};