簡體   English   中英

Javascript對象屬性的參考錯誤

[英]Reference Error for property of Javascript Object

我已經在Google Apps腳本引擎上使用Javascript構建了一個對象,每次運行腳本時,都會收到一個參考錯誤,提示未定義uName。

這是相關代碼:

function DataSet()
{
  this.uName = "";
  this.dField = "";
  this.qUrl = "http://api.bfbcs.com/api/pc?players="+uName+"&fields="+dFeilds;
  this.data = "";

  this.dQuery = dQuery;
  this.execQuery = execQuery;

根據我發現的所有消息來源,我不需要使用關鍵字var,並且在包含該關鍵字時會引發其他錯誤。

可能會發生什么?

謝謝

嗯,是的,變量uName 沒有定義,在您發布的片斷。 既不是dQuery還是execQuery ,也不是dFeilds (拼寫!)。 它們是否來自您未顯示給我們的其他代碼?

有一個屬性 this.uName ,但對象屬性與JavaScript中的變量完全不同。 與Java不同,它們不共享名稱空間。

另外,您需要對參數進行URL編碼。 例如。:

this.qUrl = "http://api.bfbcs.com/api/pc?players="+encodeURIComponent(this.uName)+"&fields="+encodeURIComponent(this.dField);

我不確定您要做什么,但是我看不到您的函數收到這些參數:

function DataSet(uName,dFeilds,dQuery,execQuery)
{
  this.uName = "";
  this.dFeild = "";
  this.qUrl = "http://api.bfbcs.com/api/pc?players="+uName+"&fields="+dFeilds;
  this.data = "";

  this.dQuery = dQuery;
  this.execQuery = execQuery;

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM