iNET Interactive - Online Advertising Agency
          
   Home    Authors    About    Login    Contact Us
   Search:   
Advanced Search     
  Articles

  ASP (26)
  ASP.NET (19)
  C and C++ (4)
  CFML (2)
  CGI and Perl (16)
  Flash (2)
  Java (7)
  JavaScript (28)
  PHP (92)
  MySQL (13)
  MSSQL (3)
  HTML (35)
  SEO (9)
  Visual Basic (12)
  CSS (13)
  SSI (5)
  XML (12)
  C# (14)

  Developer News

July 2, 2009
June Stats: What's Happening at Web Design @ About.com
About
 
July 2, 2009
Get free RSS feeds on 500 topics or make your own custom feeds!
WebDevTips UK
 
July 2, 2009
Microsoft's Bing Takes a Nibble Out of Google's Search Share
WebDevTips UK
 
July 2, 2009
States fire shots in Internet sales tax war
WebDevTips UK
 
July 2, 2009
Mrs Slocombe's pussy vanishes from Twitter
WebDevTips UK
 
July 2, 2009
More privacy choices in Facebook revamp
WebDevTips UK
 
Courtesy of moreover.com
 
Want to receive new articles via e-mail? Click here!
/Home /JavaScript

Object Oriented Javascript 

  Views:    16540
  Votes:    6
by George Jempty 3/27/05 Rating: 

Synopsis:

A demonstration of data hiding in Javascript to prove that it is indeed a bona fide object-oriented language
Pages: firstback2 forwardlast
The Article

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.
Pages: firstback2 forwardlast

Similar/related articles:


 
  Sponsors