javascript: getOwnPropertyNames
2019-05-06 本文已影响0人
已不再更新_转移到qiita
Object.getOwnPropertyNames
是es5中新增的方法,用来获取对象自身的全部属性名。
function getAllMethods(obj) {
return Object.getOwnPropertyNames(obj).filter(function(property) {
return typeof obj[property] == 'function';
});
}
console.info(getAllMethods(Math));
// abs acos acosh asin asinh atan atanh atan2 ceil cbrt expm1 clz32 cos cosh
// exp floor fround hypot imul log log1p log2 log10 max min pow random round
// sign sin sqrt tan tanh trunc sinh clamp degrees fscale iaddh isubh imulh
// radians scale umulh signbit
参考:
https://yanhaijing.com/javascript/2015/05/08/member-of-object/
https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Object/getOwnPropertyNames
https://stackoverflow.com/a/2946616