Javascript get_object_vars
Returns an array of object properties
Example 1
Running
1.function Myclass () {this.privMethod = function(){}}
2.Myclass.classMethod = function () {}
3.Myclass.prototype.myfunc1 = function () {return(true);};
4.Myclass.prototype.myfunc2 = function () {return(true);}
5.get_object_vars('MyClass')
Could return
1.{}
function get_object_vars (obj) {
// Returns an array of object properties
//
// version: 902.123
// discuss at: http://phpjs.org/functions/get_object_vars
// + original by: Brett Zamir
// * example 1: function Myclass () {this.privMethod = function(){}}
// * example 1: Myclass.classMethod = function () {}
// * example 1: Myclass.prototype.myfunc1 = function () {return(true);};
// * example 1: Myclass.prototype.myfunc2 = function () {return(true);}
// * example 1: get_object_vars('MyClass')
// * returns 1: {}
var retArr = {}, prop = '';
for (prop in obj) {
if (typeof obj[prop] !== 'function' && prop !== 'prototype') {
retArr[prop] = obj[prop];
}
}
for (prop in obj.prototype) {
if (typeof obj.prototype[prop] !== 'function') {
retArr[prop] = obj.prototype[prop];
}
}
return retArr;
}
|
HTML code for linking to this page:
Related in same category :
-
-
-
-
-
-
-
|