getMethodAndPropertys
<SCRIPT LANGUAGE="JavaScript">
<!--
function getMethodAndPropertys(obj) {
var result = [];
for (var id in obj) {
try {
if (typeof(obj[id]) == "function") {
result.push("function " + id + ": " + obj[id].toString());
}
else {
result.push("property " + id + ": " + obj[id].toString());
}
} catch (err) {
result.push(id + ": inaccessible");
}
}
return result;
}
/*
以下为测试代码
*/
function demo(bbb){
this.a=bbb;
this.display=function (){
var obj = this.a;
var ccc = navigator;
document.write(getMethodAndPropertys(ccc).join("<br/>"));
}
}
oDemo1=new demo('oDemo1');
oDemo1.display();
//-->
</SCRIPT>
JavaScript 笔记-- 打印对象的方法与属性
最新推荐文章于 2025-04-09 16:54:16 发布