This is a task that looks easy at first sight, but when you start to actually do it, things becomes a little bit complex.

The naive way is a simple for in loop.

 
var APP = window.APP || {}
 
(function(){
    APP.msg = function(message) {
        console.log(message)
    }
 
    APP.listProperty = function(obj) {
        for (var p in obj) {
            APP.msg("property name:" + p + " property value: " + obj[p])
        }
    }
})()
 
(function(){        
 
    APP.testSimpleListProperty = function(){
        var a = { p1 : 3, p2 : "Hello"}
 
        APP.listProperty(a)
    }
 
    APP.testSimpleListProperty()
})()
 

But the prototype thing will make it fail .

 
 
(function(){
    Object.prototype.bar = "bar"
 
    APP.testSimpleListProperty = function(){
        var a = { p1 : 3, p2 : "Hello"}
 
        APP.listProperty(a)
    }
 
    APP.testSimpleListProperty()
})()
 
 

Will list the property "bar".

 
property name:p1 property value: 3 
property name:p2 property value: Hello 
property name:bar property value: bar 
 

Our second version will be

 
    APP.listProperty = function(obj) {
        for (var p in obj) {
            if( obj.hasOwnProperty(p) ) {
                APP.msg("property name:" + p + " property value: " + obj[p])
            }
        }
    }
 
 

But soon you will need a recursive version for nested object.

 
    APP.listPropertyRecursive = function(obj, depth) {
        var indentation = ""
        for( var i = 0 ; i < depth * 4 ; i++) {
            indentation += " "
        }
        for (var p in obj) {
            if( obj.hasOwnProperty(p) ) {
                APP.msg(indentation + "property name:" + p + " property value: " + obj[p])
 
                if ( APP.typeInfer.isObject(obj[p]) ) {
                    APP.listPropertyRecursive(obj[p], depth + 1)
                }
 
            }
        }
    }
 

The typeInfer will be a simple function that determine whether the argument is an object. Lets test this function .

 
 
    APP.testRecursiveListProperty = function () {
        var a = { p1 : 3, p2 : "Hello"}
 
        var b  = { p1 : 4, p2 : a, p3: "World"}    
 
        APP.listPropertyRecursive(b, 0)
    }
    APP.testRecursiveListProperty()
 

The nested structure will looks like this with indentation.

 
property name:p1 property value: 4 
property name:p2 property value: [object Object] 
    property name:p1 property value: 3 
    property name:p2 property value: Hello 
property name:p3 property value: World