Monday, March 06, 2006

Object-based vs. object oriented and built-in functions

Continuing on with my quest to master the JavaScript language I am going to find out whether or not “object-based”(JavaScript) is different from object-oriented and if so, how? Also, I will discuss what built-in functions are available for JavaScript and tell you which I find the most useful and why.

When searched on Wikipedia “Object-based” programming is defined as “a somehow limited version of object-oriented programming where one or more of the following restrictions applies: there is no implicit inheritance, no polymorphism, and only a very reduced subset of the available values are objects, typically the GUI components.”
Objects in object-based languages are complete packages; everything that describes the implementation of the object is self-contained. One object doesn't share its implementation with any other objects. There is also no way to group a set of objects as a generic type. The ability to group a set of classes under a generic class is at the root of object oriented programming (polymorphism).

In addition, object-based is also referred to as prototype-based. According to Wikipedia, “Prototype-based programming is a style and subset of object-oriented programming in which classes are not present, and behaviour reuse (known as inheritance in class-based languages) is accomplished through a process of cloning existing objects which serve as prototypes.”

Now on to built-in functions…

Some top-level functions that are built-in to JavaScript are eval, parseInt, and parseFloat. The eval function takes a string as its argument and is useful for evaluating a string representing an arithmetic expression. Its argument is not limited to just evaluating numerical expressions. Its argument can include object references or even JavaScript statements. parseInt and parseFloat return a numeric value when given a string as an argument. paseInt attempts to return an int and parseFloat attempts to return a floating-point number. If either function is unsuccessful, then it returns “NaN” (not a number). If they encounter a character that is not a numeral in the specified radix, they ignore it and truncate the remaining characters, returning the converted digits.

JavaScript also has three built-in objects and can be used in either client or server scripts: string, Math, and Date. For more information of the functions that each object incorporates check out:
http://docsrv.sco.com/INT_netscapeJava/builtin.htm

The function that I find the most useful depends obviously on what the programmer is trying to accomplish but I like the eval function because of its ability to accept and evaluate arguments of different data types.