you're reading...
News, Tech

Difference between class and object, and function and method

The most obvious difference from a class and an object is that classes serve only one purpose, they are the template from which objects inherit properties and functionality. A class is like a blueprint from which a house is built.

In JavaScript there are no classes. Instead, each object can function as a class, meaning that every object can be useful in two ways: as a template for other objects, and as an object in its own right.

An object is a collection of functions and data.
A function is a collection of commands and data. When a bunch of functions work together to perform a certain task we may call this community of functionality an object.

Traditionally in Object oriented Programming, when a function is part of an object, it is called a method. But a method can be more than a function, a method is a set of functionality that acts to enhance an object. Sometimes a method has more than one function inside of itself and therefore we can’t really say that methods and functions are synonymous. Their classification can have different meanings, such as one function, or a set of functions coming together to create a method for an object.

To make things more complex, in JavaScript a function is also an object since almost everything in JavaScript is an object in its own right.

By: tony de araujo


About Admin

#WP #D


No comments yet.

Leave a Reply


You are commenting using your account. Log Out / Change )

Twitter picture


Facebook photo


Google+ photo


Connecting to %s

%d bloggers like this: