The method is a function associated with an instance of class (object).
The method is just a function declared inside a type (class/struct/enum)
(上句的 type 是指 Swift 的 type)
結論:以 js 來說,在 class 內宣告的 function,稱為 method
呼叫方式:
js 中的 method ,比較好聯想的是 js Built-In Methods,
例如:string 就會有 toLowerCase() 的 method, array 就會有 filter(), 物件導向的思考
function
A function is a piece of code that is called by name.
結論:以 js 來說,宣告在 class 外的 functions 就是 function
呼叫方式:在 call function 時可以帶入需要的 arguments
method
The method is a function associated with an instance of class (object). The method is just a function declared inside a type (class/struct/enum) (上句的 type 是指 Swift 的 type) 結論:以 js 來說,在 class 內宣告的 function,稱為 method 呼叫方式: js 中的 method ,比較好聯想的是 js Built-In Methods, 例如:string 就會有 toLowerCase() 的 method, array 就會有 filter(), 物件導向的思考
function
A function is a piece of code that is called by name. 結論:以 js 來說,宣告在 class 外的 functions 就是 function 呼叫方式:在 call function 時可以帶入需要的 arguments
reference
GiveMePasS's Android惡補筆記 ios_dev_alb Methods and Functions