Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsGeneralPHPASPPerlColdFusionFlashHTML, CSS, ScriptsBrowsers

Webmaster Forum / HTML, CSS, Scripts / JavaScript / December 2005



Tip: Looking for answers? Try searching our database.

language help

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Nan Li - 30 Dec 2005 19:52 GMT
I was reading the code of Bookburro greasemonkey user javascript.  I
don't understand some of the language features the author has used.

For example, in the following code,

var handlers = [
 { name: 'Abebooks.com', id: 'abebooks', hostname: /\babebooks.com$/i,
getISBN: /(?:isbn|bi)=([0-9X]{10})(&|\?|$)/i,
   bookURL:
'http://www.abebooks.com/servlet/SearchResults?isbn=%s&pid='+
abebooks_pid +'&aid='+ abebooks_aid,
   ajaxPrice: /<span class="price">\D*(\$[^<]*)/i },
 { name: 'Ad Libris', id: 'alse', hostname: /\badlibris\.se$/i,
   bookURL: 'http://www.adlibris.se/shop/product.asp?isbn=%s',
   ajaxPrice: function( html, http )
   {
     if( html.match( 'Ingen titel med detta ISBN finns hos AdLibris.'
) )
    return '';
     return SEK( html.match( '<span class="price">([^<]*)<' )[1] );
   } },
   ......

];

1. var handlers = [ { .. }, ..., {... } ];
  what does this mean? Is 'handlers' an array?

2. { name: 'xxx' , id: 'yyy' , ... }
  Is this an associative array?

I have not seen this kind of js code before. Can any one let me know
what they are or point me to any good reference books or websites?

Thanks a lot.
web.dev - 30 Dec 2005 20:09 GMT
> 1. var handlers = [ { .. }, ..., {... } ];
>    what does this mean? Is 'handlers' an array?

Yes, that is a shorthand for creating an array.  In this case, it
appears handlers is an array of 1..n objects.

> 2. { name: 'xxx' , id: 'yyy' , ... }
>    Is this an associative array?

The above expression is the syntax for creating an object literal which

is defined in ECMAScript v3.  It allows you to create an object and
specify its properties.  It consists of a comma-separated list of
colon-separated property/value pairs.  So in your above expression, you

have an object with properties "name" and "id" whose corresponding
value is "xxx" and "yyy".
Jasen Betts - 31 Dec 2005 00:50 GMT
> 1. var handlers = [ { .. }, ..., {... } ];
>    what does this mean? Is 'handlers' an array?

yes.

> 2. { name: 'xxx' , id: 'yyy' , ... }
>    Is this an associative array?

no, an object.
which behaves somewhat like an associative array does in other languages
but also somewhat differently.

> I have not seen this kind of js code before. Can any one let me know
> what they are or point me to any good reference books or websites?

Bye.
  Jasen
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.