+ 1

what are the difference between functions and object?

5th Sep 2016, 5:33 PM
Vijay Kumar
Vijay Kumar - avatar
4 Answers
+ 4
They have little in common, so I'm wondering why you are asking the question. A function does a task, an object contains data (that may include functions too). Maybe you are actually asking the difference between a class and an object, since you use the keyword function to declare a class. In that case, a class is like a blueprint to build objects. In a class, you define everything an object of the class should have: attributes (what it is) and methods (what it can do). Then, to actually do anything concrete, you need to instanciate objects of the class. For example, let's say you have a class to handle complex numbers. You define two attributes, re and im, for the real and imaginary part respectively, and a method sum that does the sum of two complex number. You create then two complex numbers, with different attributes, and use the sum method on those objects.
6th Sep 2016, 8:40 AM
Zen
Zen - avatar
+ 1
A function is a method. you can pass some property to it and receive the result(as a return value or an action ....) but object is like a variable, It can contains of several variables inside it and also several functions and ....
18th Sep 2016, 7:52 AM
Hassan Bagheri Valoujerdi
Hassan Bagheri Valoujerdi - avatar
0
thank you guys
7th Sep 2016, 11:58 AM
Vijay Kumar
Vijay Kumar - avatar
- 1
function has declaration to do specific job and can to call it in any place in your code but Object inherit from class (the class has some variables or has many functions)
5th Sep 2016, 6:05 PM
ahmed mokhtar
ahmed mokhtar - avatar