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

Fill in your details below or click an icon to log in: Logo

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

Google+ photo

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

Twitter picture

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

Facebook photo

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


Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: