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

前端 未结 6 2192
别那么骄傲
别那么骄傲 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:29

    Several people have explained it in similar terms, but thought I'd add that when speaking to people unfamiliar with object oriented programming, I explain that the class definition is the blueprint, as for a house, and "this" is the actual house you're working with at that moment. There might be other houses that look exactly the same, but this is the specific object (house).

提交回复
热议问题