Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Javascript (http://www.velocityreviews.com/forums/f68-javascript.html)
-   -   language help (http://www.velocityreviews.com/forums/t922167-language-help.html)

Nan Li 12-30-2005 07:52 PM

language help
 
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 12-30-2005 08:09 PM

Re: language help
 

Nan Li wrote:
> 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".



All times are GMT. The time now is 07:20 PM.

Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57