Funding for 'IT Lab' Project, Phase 1: Progress of sticker sales. Purchase a sticker to help us reach our target.Updated: 2010-02-28 11:53
Let’s Follow Web Standards

During the past series of articles
I focus your attention on various Web based technologies and their best
practices in their day today application. Today with this article I'm going to
introduce another important technology that has revolutionized the World Wide
Web over the past decade. This we can call as the world's most misunderstood
language. It's called the JavaScript. It's a small language specially designed
for work within the context a of Web browser. The JavaScript language has many
implementations like LiveScript, JScript, ECMAScript, etc... and its original
implementation was derived from LiveScript. Microsoft Corporation developed a
compatible dialect of the language, naming it JScript to avoid Trademark
issues. Today every personal computer in the world has at least one JavaScript
interpreter installed on it and in active use. Although the popularity of
JavaScript among the user community is it being just a scripting language with
limited capabilities but it's a nice, dynamic object-oriented general-purpose
programming language having features like Load and Go delivery, Loosely typed,
Prototypal Inheritance, Lambda, Linkage through global variables, Objects,
etc...
JavaScript is not Java although it
has the suffix Java appends to it. It came out as such due to the alliance that
the Netscape Corporation had with Sun Microsystems. They are two very different
languages. JavaScript is not a subset of Java. It is not interpreted Java.
JavaScript shares C-family syntax with Java, but at a deeper level it shows
greater similarity to the functional languages like Scheme and Lisp. It is a
small language, but it is also a surprisingly powerful and expressive language.
History
JavaScript was developed by Brendan Eich at Netscape
Corporation as the in-page scripting language for Netscape Navigator 2. The
original version was first called as LiveScript which ran both on client-side
as well as server-side under its special platform. As mentioned above the
JavaScript was born through the alliance of Netscape Corporation and Sun
Microsystems. Because of its linkage
to web browsers, it instantly became massively popular. It never got a trial
period in which it could be corrected and polished based on actual use. The
language is powerful and flawed. The language is not complete due to the flaws
in its standards specification which got approved in a forum held at European
Computer Manufactures Association (ECMA), a Switzerland-based standards body.
Data Types in JavaScript
JavaScript comes with a small set
of data types. It has three primitive types String, Number and Boolean
and two other special values called null and undefined. Other
than that everything in this language are considered as Objects.
String in this language is a
sequence of 0 or more 16-bit characters having a character encoding of UCS-2
not of UTF-16 and the current version supports Unicode. It has no separate
character types; it represents a character as a string of length of 1. Strings
are immutable.
Only one number type is available and there is not such
type called integers. Number is 64-bit floating point, aka IEEE-754,
similar to Java's double and Double. The division between two
integers always produces a fractional result. Number also includes the special
values
Boolean has two values, namely true and false.
Nulls always gives a null while undefined is a special value that the
default value assigned to any of the variable unless they are initialized.
Loosely typed
Reserved Words
It’s a
language with a bag full of key words that lets the programmer to get the work
done easily with minimum effort. So have to be careful in using reserve
words.
abstract
boolean break byte
case catch char class const continue
debugger default delete do double
else enum export extends
false final finally float for function
goto
if implements import in instanceof int interface
long
native new null
package private protected public
return
short static super switch synchronized
this throw throws transient true try typeof
var volatile void
while with
Objects
Eg:
var myObject = {name:
"Hayesha Somarathne", 'country': '
var theName =
myObject.name;
var country =
myObject['country'];
Instead
of creating an object directly we also can make use of the Maker
function to create one.
function maker(name,
country, gender) {
var it = {};
it.name = name;
it['country'] = country;
it.gender = gender;
return it;
}
myObject =
maker("Hayesha Somarathne", '
In the
following example you will see that JavaScript provides the facility to create
object(s) within an object.
var myObject = {
name: "Hayesha Somarathe",
'country': '
gender: 'Male',
format: {
color: 'fair',
weight: 60,
height: 168
}
};
Prototypal Inheritance
In most languages we encounter consists of classes,
methods, constructors and modules. The JavaScript’s functions do all of those.
Instead of the classical Inheritance JavaScript comes with Prototypal
Inheritance. This accomplishes the same thing but in a different manner and it
offers greater expressive power. Instead of organizing objects into rigid
classes, new objects can be made that are similar to existing objects, and then
customized. Object customization is less work than making a class, and less
overhead, too.
One of the keys is the object(o) function and other
key is functions. Objects can be passed as arguments to functions, and can be
returned by functions. They are passed by reference and not as passed by value.
Summary
Over the Internet you’ll be able to find enough articles
written on JavaScript explaining various aspects of it usage. But in this
article I tried to focus your attention on the JavaScript scripting language in
a bit of a different dimension to make you understand the real power built into
it. I have introduced a list of the language features in the beginning but have
only extend the discussion on few of them, so its up to you go further and
explore more into them to feel the real power of it and make use the language
features effectively in your future attempts.
Reference:
Douglas
Crockford, JavaScript: The Good Parts
http://developer.yahoo.com/yui/theater/
Post new comment