Skip to content

Instantly share code, notes, and snippets.

@gotomypc
Created November 5, 2012 11:37
Show Gist options
  • Select an option

  • Save gotomypc/4016809 to your computer and use it in GitHub Desktop.

Select an option

Save gotomypc/4016809 to your computer and use it in GitHub Desktop.
enumerate property in Object&Class from JavaScript
function TestProp () {
var p1 = 'abc';
var priFunc = function() {
console.log('Im private function');
}
this.privilegeFunc = function () {
console.log('Im priviledge function');
}
this.pubProp = "Public property";
}
TestProp.prototype.PubFunction = function () {
console.log("I'm public function/method");
}
TestProp.prototype.ProtoProperty = "Prototype Property";
TestProp.classProperty = "Static Class Property";
(function (){
console.log('Class Property is ' + Object.keys(TestProp));
console.log('Object Property is ' + Object.keys(new TestProp()));
console.log('try another method to list property');
var test = new TestProp();
var arr1 = [];
for (var i in test) {
arr1.push(i);
}
console.log(arr1.join('\n'));
})();
@gotomypc
Copy link
Author

gotomypc commented Nov 5, 2012

output is :
Class Property is classProperty
Object Property is privilegeFunc,pubProp
try another method to list property
privilegeFunc
pubProp
PubFunction
ProtoProperty

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment