一直对动态语言的的method obj和function obj感到困惑:
今天看了一个较好的区分介绍:
A function is a piece of code that is called by name. It can be passed data to operate on (ie. the parameters) and can optionally return data (the return value).
All data that is passed to a function is explicitly passed.
A method is a piece of code that is called by name that is associated with an object. In most respects it is identical to a function except for two key differences.
- It is implicitly passed the object for which it was called
- It is able to operate on data that is contained within the class (remembering that an object is an instance of a class - the class is the definition, the object is an instance of that data)
本文详细解释了在编程中函数和方法之间的区别。函数是一段可通过名称调用的代码,可以接收参数并返回值。而方法也是通过名称调用的代码段,但它与对象关联,并能操作对象内部的数据。
755

被折叠的 条评论
为什么被折叠?



