How to explain 'this' keyword in a best and simple way?

前端 未结 6 2219
别那么骄傲
别那么骄傲 2020-12-06 19:40

I am using \'this\' keyword for a long time. But when someone asks me to explain it, I am confused that how to explain it. I know that I can use this in a method of class to

6条回答
  •  南笙
    南笙 (楼主)
    2020-12-06 20:20

    A class is a mold for an object: it specifies how the object looks like (variables) and what it can do (functions).

    If you instanciate a class: you create an object. If you create the class, you can use "this" to refer to the object itsself. This is why you can't set the "this", because it's related to the object. It's a special, read-only variable.

提交回复
热议问题