Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Can anyone help me to undrstnd the output of the below code

  let obj1 ={
    fName : 'Ayush',
    lName : 'Singh',
    city: 'Asansol',
    getName : function(){
      console.log(`I am ${this.fName} ${this.lName} from ${this.city}`)
    }
  }
  let obj2 = {
    fName : 'Aman'
  }

  obj2.__proto__ = obj1;

  console.log(obj1.getName())
  obj2.getName()
  console.log(obj2.__proto__.getName())
  console.log(obj1.__proto__.getName())

Here I am trying to check how proto works. Why can’t I access of obj1.proto.getName

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Deprecated: This feature is no longer recommended. Though some browsers might still support it, it may have already been removed from the relevant web standards, may be in the process of being dropped, or may only be kept for compatibility purposes. Avoid using it, and update existing code if possible; see the compatibility table at the bottom of this page to guide your decision. Be aware that this feature may cease to work at any time.

how proto work is it as getter and setter of object.

why your obj1.proto doesnot work because you have not set it. you only set it for obj2.

more ref from docs :-

Object.prototype.proto

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading