试试这个:
alert((obj.c!=undefined)?obj.c:"Undefined");
要真正回答你的问题,你不应该找一个对象不存在的属性或方法。如果你碰巧在循环一个对象属性,你使用[]符号而不是点符号,比如。
var x, obj = {...}
for(x in obj){
alert("Property name:"+x+" | value: "+obj[x]);
}
而且可以随时换任何说法是值得商榷的一个try/catch。
或函数,而不是对象常量:
var obj = function(Params){
this.URL = "";
this.QueryString = new Array();
this.Params = Params;
this.Method = "POST";
this.CallBack = "";
this.OnSuccess = "";
this.OnFailure = "";
this.Header = "application/x-www-form-urlencoded";
this.Response = "";
for(var Param in this.Params){
switch (Param){
case 'URL' : this.URL = this.Params[Param]; break;
case 'QueryString' : this.QueryString = this.Params[Param];break;
case 'Header' : this.Header = this.Params[Param]; break;
case 'Method' : this.Method = this.Params[Param]; break;
case 'CallBack': this.CallBack = this.Params[Param]; break;
case 'OnSuccess': this.OnSuccess = this.Params[Param]; break;
case 'OnFailure': this.OnFailure = this.Params[Param]; break;
case default: something(); break; //I just don't have this line because I didn't need a default;
}
}
}
以上是开始一个Ajax对象我写的,但你的想法..
老兄......我想你会尽你所能为一些非标准数据设置自定义getter和setter以及处理程序。你是为了某些客户端功能而编写的,还是这是一些SSJS? – Relic 2012-01-30 00:57:03