By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,340 Members | 1,715 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,340 IT Pros & Developers. It's quick & easy.

javascript class syntax I have not seen before...

P: n/a
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

Oct 29 '07 #1
Share this Question
Share on Google+
1 Reply


P: n/a
On Oct 29, 11:36 am, Cartoper <carto...@gmail.comwrote:
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 nameof the object <object
nameand 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 >
--
Rob

Oct 29 '07 #2

This discussion thread is closed

Replies have been disabled for this discussion.