試試這個:
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