日期:2014-05-16  浏览次数:20310 次

自定义一个方法原型,取得json对象某个值
Object.prototype.k = function(n, t){
       var arr = [];   
       for (pro in this) arr.push(pro);
       return t ? arr[n] : this[arr[n]]
}

一个json对象:
var Tabs = {
	"全部":"pages/page1.html",
	"歪歪":"pages/page2.html",
	"照片":"pages/page3.html",
	"表情":"pages/page4.html"
}


alert(Tabs.k(0,0))   //pages/page1.html
alert(Tabs.k(0,1))   //全部
alert(Tabs.k(1,1))   //歪歪