Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

What is the difference between a method and a function? Is it that a method returns a value and a function doesn't?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
205 views
Welcome To Ask or Share your Answers For Others

1 Answer

Method is actually a function used in the context of a class/object.

When you create a function outside of a class/object, you can call it a function but when you create a function inside a class, you can call it a method.

class foo {
   public function bar() { // a method
     ........
   }
}

function bar() {  // a function not part of an object
}

So an object can have methods (functions) and properties (variables).


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...