开发者

Reference Error for property of Javascript Object

开发者 https://www.devze.com 2022-12-27 20:03 出处:网络
I have built an object in Javascript on the Google Apps Script engine and every time I run my script I get a reference error saying uName is not defined.

I have built an object in Javascript on the Google Apps Script engine and every time I run my script I get a reference error saying uName is not defined.

Here is the relivant co开发者_如何学运维de:

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;

According to all sources I have found, I should not need to use the keyword var, and when I do include that, it throws other errors.

What could be going on?

Thanks


Well, yes, the variable uName isn't defined, in the snippet you posted. Neither's dQuery or execQuery, or dFeilds (spelling!). Are they coming from other code you haven't shown us?

There's a property this.uName, but object properties are a completely different thing to variables in JavaScript. Unlike Java, they don't share a namespace.

Also, you need to URL-encode parameters. eg.:

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


I am not sure what you are trying to do but I dont see your function receiving those parameters:

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;
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号