Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Javascript General Javascript discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old May 24th, 2005, 02:13 PM
Registered User
 
Join Date: May 2005
Location: , , .
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default Object literal syntax

I am familiar with this type of literal object syntax:
Code:
var myObject = {"bindings": [
        {"ircEvent": "PRIVMSG", "method": "newURI", "regex": "^http://.*"},
        {"ircEvent": "PRIVMSG", "method": "deleteURI", "regex": "^delete.*"},
        {"ircEvent": "PRIVMSG", "method": "randomURI", "regex": "^random.*"}
    ]
};
as well as this, for arrays:
Code:
slides = [
    {url: 'slide0001.html', title: 'Looking Ahead'},
    {url: 'slide0008.html', title: 'Forecast'},
    {url: 'slide0021.html', title: 'Summary'}
];
but the following is new to me:
Code:
obj[‘on’ + event]
What does this mean? obj is an object, I think.

Thanks,
Tim

Reply With Quote
  #2 (permalink)  
Old May 25th, 2005, 12:14 PM
Registered User
 
Join Date: May 2005
Location: , , .
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Update:

So I've figured out that obj["on" + event] is an object, and that it's object property syntax (e.g. obj["property"]).

What is still confusing me is the + event part. Does the "on" + event just resolve to a string (given that event would be a reference to another object)?

Reply With Quote
  #3 (permalink)  
Old May 27th, 2005, 03:07 PM
nzakas's Avatar
Wrox Author
 
Join Date: Dec 2004
Location: Peabody, MA, USA.
Posts: 217
Thanks: 0
Thanked 5 Times in 5 Posts
Default

Yes, it does resolve to a string because anything plus a string equals a string. Of course, what that final value is will depend on the value of the event variable.

Nicholas C. Zakas
Author, Professional JavaScript for Web Developers (ISBN 0764579088)
http://www.nczonline.net/
Reply With Quote
  #4 (permalink)  
Old May 28th, 2005, 11:47 AM
joefawcett's Avatar
Wrox Author
Points: 9,763, Level: 42
Points: 9,763, Level: 42 Points: 9,763, Level: 42 Points: 9,763, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Exeter, , United Kingdom.
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

To clarify:
Code:
obj[‘on’ + event]
if event = "click" then
 the above equals:
Code:
obj["onclick"]
which is the same as:
Code:
obj.onclick
Presumably the author was tring to dynamically assign event handlers.


--

Joe (Microsoft MVP - XML)
Reply With Quote
  #5 (permalink)  
Old May 28th, 2005, 07:44 PM
Registered User
 
Join Date: May 2005
Location: , , .
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

@ Joe & Nicholas: Thanks.

@ Joe: yes, I can see now that that's exactly what the author was doing.

Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Label vs Literal pinch BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 2 October 9th, 2007 01:01 PM
Object reference Syntax help lidanny General .NET 5 September 3rd, 2006 07:17 AM
Fields object syntax in VBA query stepdev Access VBA 11 March 3rd, 2006 04:53 PM
Using right() to return a literal value Somed00d Access 4 February 8th, 2006 02:56 PM
Syntax for OleDb Command Object Parameters aadz5 ASP.NET 1.0 and 1.1 Basics 4 November 20th, 2003 03:31 PM



All times are GMT -4. The time now is 12:10 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.