如何获取对象的方法? [英] How to get an object's methods?
本文介绍了如何获取对象的方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
$ b
function foo(){}
foo.prototype.a = function(){}
foo.prototype.b = function(){}
foo.get_methods(); //返回['a','b'];
更新:在Jquery中是否有类似的方法?
谢谢。
解决方案
function getMethods(obj)
{
var res = [];
for(var m in obj){
if(typeof obj [m] ==function){
res.push(m)
}
}
return res;
}
Is there a method or propertie to get all methods from an object? For example:
function foo() {}
foo.prototype.a = function() {}
foo.prototype.b = function() {}
foo.get_methods(); // returns ['a', 'b'];
UPDATE: Are there any method like that in Jquery?
Thank you.
解决方案
function getMethods(obj)
{
var res = [];
for(var m in obj) {
if(typeof obj[m] == "function") {
res.push(m)
}
}
return res;
}
这篇关于如何获取对象的方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文