javascript class syntax I have not seen before...

C

Cartoper

I have this book "Beginning JavaScript for Practical Web Development,
Including AJAX" and in it the author is using javascript syntax I
don't understand. It is

<class name>={
<function name>:function(params)
{
},
<function name>:function(params)
{
},
};

Here is a snippet of the actual code:

DOMhelp={
debugWindowId:'DOMhelpdebug',
init:function(){
// removed
},
lastSibling:function(node){
// removed
},
}

Are these static functions of the class DOMhelp or is something else
going on? Can someone provide me with a link that will expain this
notiation to me?

Cartoper
 
R

RobG

I have this book "Beginning JavaScript for Practical Web Development,
Including AJAX" and in it the author is using javascript syntax I
don't understand. It is

<class name>={

That is an example of object literal notation that results in an
object being assigned to a (global) variable.

There are no classes in javascript (i.e. ECMAScript Language Ed 3)
although "class" is a future reserved word and there are plans to
introduce classes in the next version of ECMAScript. It is best not
to think of classes in regard to javascript, it just makes life more
difficult. You can emulate certain features of classes that exist in
other languages, however that does not make classes exist in
javascript.

All variables should be declared with var, though some are lazy and
don't bother for global variables. To me, it is much better to
explicity declare them:

var <object name> = { ... };

It makes maintenance easier.

<function name>:function(params)
{
},

That creates a property called <function name> of the object <object
name> and assigns it a value of the function expression. You can call
it with:

<object name>.<function name>();


[...]
Are these static functions of the class DOMhelp or is something else
going on? Can someone provide me with a link that will expain this
notiation to me?

<URL: http://www.crockford.com/javascript/private.html >
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,527
Members
44,998
Latest member
MarissaEub

Latest Threads

Top