LoginSignup
0
0

More than 1 year has passed since last update.

javascript: getOwnPropertyNames

Posted at

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

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0