有没有一种方法可以打印对象的所有方法? [英] Is there a way to print all methods of an object?
本文介绍了有没有一种方法可以打印对象的所有方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有没有办法在JavaScript中打印对象的所有方法?
Is there a way to print all methods of an object in JavaScript?
推荐答案
确定:
function getMethods(obj) {
var result = [];
for (var id in obj) {
try {
if (typeof(obj[id]) == "function") {
result.push(id + ": " + obj[id].toString());
}
} catch (err) {
result.push(id + ": inaccessible");
}
}
return result;
}
使用它:
alert(getMethods(document).join("\n"));
这篇关于有没有一种方法可以打印对象的所有方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文