1. 程式人生 > >類的方法叫function,例項的方法叫method

類的方法叫function,例項的方法叫method

By definition, all attributes of a class that are function objects define corresponding methods of its instances.

根據定義,所有類的屬性是函式物件的,定義了對應的例項的方法。

In general, calling a method with a list of n arguments is equivalent to calling the corresponding function with an argument list that is created by inserting the method’s instance object before the first argument.

通常來說,呼叫n個引數的例項方法,相當於呼叫對應的類函式,且類函式的引數是n個引數前面再加一個例項物件。

If you still don’t understand how methods work, a look at the implementation can perhaps clarify matters. When a non-data attribute of an instance is referenced, the instance’s class is searched. If the name denotes a valid class attribute that is a function object, a method object is created by packing (pointers to) the instance object and the function object just found together in an abstract object: this is the method object. When the method object is called with an argument list, a new argument list is constructed from the instance object and the argument list, and the function object is called with this new argument list.