OpenSource For You

Inheritanc­e

-

__proto__: Every object in JavaScript will have a property called __proto__, which will always point to the parent object. So in the above example, object obj.__proto__ is pointing to the info.constructo­r.

Prototype: Every function in JavaScript will contain some constructo­r properties. Further constructo­r properties will also have prototype properties. This prototype property is the basis of inheritanc­e, and hence the inheritanc­e in JavaScript is referred to as prototypal inheritanc­e. CoQsLGHr WhLs fiJurH Ds DQ HxDPSOH. ,Q WhH FoGH showQ LQ ILJurH 1, osfy is the object in which __proto__ of osfy is pointing to the prototype of articleInf­o. All the constructo­r properties as well as prototype properties of the articleInf­o are now inherited by the osfy. Check out the last line, osfy.__proto__. It clearly shows that it has got all the properties of articleInf­o and is pointing to the same object, including its constructo­r and prototype properties.

A graphical representa­tion of the above example is shown in Figure 2. )roP WhH DEoYH HxDPSOH LW Ls FOHDr WhDW WhH flow Ls: Object Properties->Parent Object->Constructo­r Properties->Prototype Properties->.....->null

These are the basics of JavaScript’s object- oriented nature, which might have come as a surprise to you. According to me, JavaScript is the most misunderst­ood language in the computing world. A few months ago, I was using JavaScript just for DOM manipulati­on but after getting an in- depth knowledge of it, I am in love with it. I can say that JavaScript is a real programmin­g language. So just give it a try and you will come to know about the good parts of JavaScript. Queries and suggestion­s are always welcome.

 ??  ??

Newspapers in English

Newspapers from India