Skip to content

Commit

Permalink
Added explaination to Question
Browse files Browse the repository at this point in the history
  • Loading branch information
malipramod committed Dec 3, 2019
1 parent 3c6405c commit c6439af
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3418,7 +3418,26 @@ personObj.getName2();
Answer: 2) Tony undefined
Explaination: **getName1()** function works fine because it's being called from ***personObj***, so it has access to *this.name* property. But when while calling **getnName2** which is defined under *Object.prototype* doesn't have any proprty named *this.name*. There should be *name* property under prototype. Following is the code:
```javascript
function getName1(){
console.log(this.name);
}

Object.prototype.getName2 = () =>{
console.log(Object.getPrototypeOf(this).name);
}

let personObj = {
name:"Tony",
print:getName1
}

personObj.print();
Object.prototype.name="Steve";
personObj.getName2();
```
## Contributing
Expand Down

0 comments on commit c6439af

Please sign in to comment.