See js panel and console for demo of showObjectProperties() experiment.
JavaScript
function showObjectProperties(obj, options) {
if (typeof obj !== 'object') {
return;
}
var options_default = {show_get_methods: false};
options = (typeof options === 'object') ? options : {};
options = Object.assign({}, options_default, options);
console.groupCollapsed('showObjectProperties: ' + obj.constructor.name);
console.log(obj);
console.log('.constructor.name:', obj.constructor.name);
var property_result, v;
var property_results = [];
// TODO: use for..in with hasOwnProperty(), or use Object.getOwnPropertyNames() ?
// for(p in obj) {
// if (!obj.hasOwnProperty(p)) { continue; }
Object.getOwnPropertyNames(obj.__proto__).forEach(function(p,i){
v = obj[p];
property_result = {
property: p,
value_type: v === null ? 'null' : typeof v,
value: v
};
if (typeof v === 'object') {
try {
property_result.constructor_name = v.constructor.name;
} catch (e) {}
}
if (options.show_get_methods && typeof v === 'function' && p.match(/^(get|to)[A-Z_]/) ) {
// EXPERIMENTAL warning!
// Calling functions could modify original object or do other things.
// Usually methods like: getXxx() toXxx() get_xxx() to_xxx()
// only return a value and do not change other things,
// but that is not a guarantee.
try {
// calling v() throws an error:
// TypeError: Method Date.prototype.toString called on incompatible receiver undefined
// property_result.f_value = v();
// but calling obj[p](); is ok.
property_result.f_value = obj[p]();
} catch (e) {
property_result.f_value_error = e;
}
}
property_results.push(property_result);
// }
});
console.table(property_results);
console.groupEnd();
}
showObjectProperties((new Date()), {show_get_methods:true});
showObjectProperties(document.body, {show_get_methods:true});
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.