What "this" can do in js? | SoloLearn: Learn to code for FREE!

+1

What "this" can do in js?

4/29/2020 3:37:53 AM

Алинур Кадыр уулу

2 Answers

New Answer

0

The JavaScript this keyword refers to the object it belongs to. In object method this refers to the owner of the method. It's values depending on where it is used. Let's say there is the method object called person as var person = { firstName: "John", lastName : "Doe", fullName : function() { return this.firstName + " " + this.lastName; } }; This is object method in which 'this' refers to the person object. Now 'this' keyword in event handler is used as <button onclick="this.style.display='none'"> So in above 'this' refers to the button element. I hope you''ll understand. Thanks!

0

I know "this" refers to the owner of method. I should write it. But is this all what "this" can do? Thanks for answer!