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

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

    A class is a template or a 'die' for an object.

    Lets use the classic 'bicycle' example. There are many huffy bikes out there. However, we have created one bike, and we can use the 'this' keyword to refer to 'this' bike.

    In more a more technical sense, a class is a template for an object that will be instantiated. At run time, after an object has been instantiated, or had an instance of itself created, we can then use the keyword 'this' internally to refer to the instance that runs that method.

提交回复
热议问题