美文网首页
javascript: getOwnPropertyNames

javascript: getOwnPropertyNames

作者: 已不再更新_转移到qiita | 来源:发表于2019-05-06 13:28 被阅读0次

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

相关文章

网友评论

      本文标题:javascript: getOwnPropertyNames

      本文链接:https://www.haomeiwen.com/subject/touroqtx.html