Get all functions of an object in JavaScript
问题 For example, Math.mymfunc = function (x) { return x+1; } will be treated as a property and when I write for(var p in Math.__proto__) console.log(p) it will be shown. But the rest of Math functions will not. How can I get all functions of a Math object? 回答1: Object.getOwnPropertyNames(Math); is what you are after. This logs all of the properties provided you are dealing with an EcmaScript 5 compliant browser. var objs = Object.getOwnPropertyNames(Math); for(var i in objs ){ console.log(objs[i]