Monday 15 September 2014

javascript - Why doesn't for...in print out properties from Object? -


I have written the following javascript and are expected to see all the properties from obj2 with the items listed with the properties being expected (Which I thought) base class - why do not I see properties like prototype and tostrings listed with one more two?

  Obj2 = function () {this.one = "one"; this. Two = "two"; } Var obj2 = new Obj2 (); For (obj2 in var i) {try {console.log (i + ":" + obj2 [i]); } Hold (e) {console.log (i + "error occurred:" + e); }}    

Just like LAN has said for

> Function Obj2 () {this.one = "one"; this. Two = "two"; } Var obj2 = new Obj2 (), proto = obj2, keys = Object.getOwnPropertyNames (proto); While (Proto) {for (keys in var i) {try {console.log (keys [i] + ":" + proto [key] [i]]); } Hold (e) {console.log (i + "error occurred:" + e); }} Proto = Object.getPrototypeOf (proto); Key = protozes? Object.getOwnPropertyNames (proto): zero; }

No comments:

Post a Comment