javascript - Idiom to get just the "own object" and not the prototype chain -


is there recognised idiom own-object in javascript? i.e. chop off prototype chain object, in ie10 , above.

function o() {   this.foo = 'foo'; } o.prototype = { bar: 'bar' }  var o = new o();  for(var v in o) {    console.log(v); // foo bar }  // ...but want object representing own properties , values  o.__proto__ = null; // need work in ie10 for(var v in o) {    console.log(v); // foo } 

you using object.getownpropertynames() or object.keys().

fiddle demo

function o() {   this.foo = 'foo'; } o.prototype = { bar: 'bar' }  var o = new o();  for(var v in o) {      console.log(v); // foo bar }  object.getownpropertynames(o).foreach(function(val, idx, array) {   console.log("getownpropertynames() " + val); });  object.keys(o).foreach(function(val, idx, array) {   console.log("keys() " + val); }); 

Comments

Popular posts from this blog

android - How to save instance state of selected radiobutton on menu -

python 3 IndexError: list index out of range -

IF statement in MySQL trigger -