Created
November 5, 2012 11:37
-
-
Save gotomypc/4016809 to your computer and use it in GitHub Desktop.
enumerate property in Object&Class from JavaScript
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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')); | |
| })(); |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
output is :
Class Property is classProperty
Object Property is privilegeFunc,pubProp
try another method to list property
privilegeFunc
pubProp
PubFunction
ProtoProperty