Javascript
is an object-oriented programming language.
Don't
believe me? Consider the following:
ECMAScript
is an object-oriented programming language.
This
is directly from the ECMAScript Language Specification
(NOTE: this is a 188 page PDF that could take a couple of minutes to
completely download on a dialup connection), which, as a point of
definition, additionally states: This
ECMA Standard is based on several originating technologies, the most
well known being JavaScript. Regarding ECMA, for
over forty years (they have) actively contributed to world-wide
standardization in information technology and telecommunications,
and they know an object oriented-language when they see one: they've also developed the standards for C# and Eiffel.
Let
me try this again:
Javascript
is an object-oriented programming language.
Still
not convinced? Let's start with a definition of object-oriented
programming:
The
use of a class of programming languages and techniques based on the
concept of an 'object'
which is a data structure (abstract data type)
encapsulated with a set of routines, called 'methods',
which operate on the data. Operations on the data can _only_ be
performed via these methods (emphasis
added; see http://foldoc.doc.ic.ac.uk/foldoc/foldoc.cgi?object-oriented+programming).
To confirm that Javascript fits the bill, at least as far as the
first sentence, please read the ECMAScript standard.
It's
with regard to the second provision that Javascript has gotten a bum
rap. The myth that data hiding -- operations on data only via
methods is lacking from Javascript, has been perpetuated not just
by run of the mill naysayers, but even by authors of books about
Javascript!
Consider
this code excerpt:
|
function Square(size) {
this.dimension = size;
this.area = size * size;
}
var object1 = new Square(4);
|
As
you can see, functions in Javascript also serve as object constructors,
but that is not the point. The authors of the book containing this
snippet go on to state that in JavaScript, once the above objects are
created there's nothing stopping you from getting at the dimension
property.
WRONG!!
To the authors' credit, this got cleared up in a subsequent edition of
the book. But once this sort of myth gets started, there is no shaking
some people, and that is one reason why Javascript has such a bad
reputation to this day.