How to get an object's methods?

前端 未结 12 1138
暗喜
暗喜 2020-12-13 03:33

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()         


        
12条回答
  •  失恋的感觉
    2020-12-13 03:42

    In ES6:

    let myObj   = {myFn : function() {}, tamato: true};
    let allKeys = Object.keys(myObj);
    let fnKeys  = allKeys.filter(key => typeof myObj[key] == 'function');
    console.log(fnKeys);
    // output: ["myFn"]
    

提交回复
热议问题