var user = {name:"vasa", age:5} Object.defineProperty(Object.prototype, "length", { get: function () { var len = 0, a; for (a in this) this.hasOwnProperty(a) && len++; return len } }); alert(user.length);