标签:sort index push javascrip reg highlight pre names function
输出实例的属性和方法以及prototype中的属性和方法,主要利用的getOwnpropertyNames()
function getper(obj) {
console.log(‘------------ 实例 ------------‘);
var arr_property = [];
Object.getOwnPropertyNames(obj).sort().forEach(function(item, index) {
if (typeof obj[item] === ‘function‘) {
arr_property.push(‘function: ‘ + item)
} else {
arr_property.push(‘property: ‘ + item)
}
})
arr_property.sort().forEach(function(value,i) {
console.log(value);
})
console.log(‘------------ prototype ------------‘);
var arr_prototype = [];
Object.getOwnPropertyNames(obj.prototype).sort().forEach(function(item, index) {
if (typeof obj.prototype[item] === ‘function‘) {
arr_prototype.push(‘function: ‘ + item)
} else {
arr_prototype.push(‘property: ‘ + item)
}
})
arr_prototype.sort().forEach(function(value,i) {
console.log(value);
})
}
//这里以正则为例
getper(RegExp);
标签:sort index push javascrip reg highlight pre names function
原文地址:http://www.cnblogs.com/liangcheng11/p/7158006.html