oop - how prototype properties are delegated to sub class from super class in javascript -


please me understand following code snippet.

var ob = {a:20,b:30}; object.prototype.c = '40'; (var x in ob){     console.log(x); // log a,b,c in console } var keys = object.keys(ob) ; console.log(keys); // log a,b in console 

my question , how putting property 'c' on prototype of 'object' make available 'ob' ?

edit: want know default constructor function called when try create object , basic responsibilities performed constructor ?

an object literal ({}) inherit object.prototype. object.prototype.c = '40'; sets c property on object's prototype, objects inheriting object able access property. properties defined on object's prototype accessible on objects inheriting it.

the difference between for (var x in ob) , object.keys(ob) object.keys(ob) return properties of ob object, whereas for (var x in ob) traverse prototype chain , find c property on object's prototype.

by default, no properties defined on object's prototype included in for-in loop not enumerable. added property enumerable default.


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -