• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

colon in javascript array declaration question

 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi,

i'm reading the oreilly flanagan javascript book. An example has me baffled as to what it is doing. javascript seems to have changed a bit in the last few years ;-) i know it creates an array, but the use of the colon is the bit i've never seen before.

var point = {x:0,y:0};
var circle = {x :p oint.x, y :p oint.y};

my questions are:-
what are the colons doing exactly?
what type of operator are they?
also can someone explain what the x :p oint.x is doing.

it obviously a shortcut. it looks like an enum but i'm still baffled.
[ March 14, 2007: Message edited by: stuart mellanby ]
 
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It is JavaScript Object Notation [JSON]

Check out JSON.org

Eric
 
Stuart Swearengen
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
the emoticons are actually meant to be : P not the dancing whatnots...
 
Eric Pascarello
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by stuart mellanby:
the emoticons are actually meant to be : P not the dancing whatnots...



We smiles in code all the time in JavaScript, it is a new fashion trend! (Make sure to click disable smiles checkbox when you post code.)

Eric
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by stuart mellanby:
i knwo ti vreates and array bu the use of the colon ...



I think your pet iguana has been walking on your keyboard again.

But no, it's not creating an array, it's creating an object instance using a JSON literal. An array is created using square bracketes (as opposed to the braces).



This is equivalent to:



Just a lot less wordy.
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
P.S. Array notation:

 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by stuart mellanby:
the emoticons are actually meant to be : P not the dancing whatnots...



When posting code, be sure to click the 'disable smilies' checkbox as Eric instructed, and use UBB code tags.

You can go back and fix your original post (including the iguana droppings) by clicking on the icon.
[ March 14, 2007: Message edited by: Bear Bibeault ]
 
Stuart Swearengen
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the answers. The errors are corrected (mostly).
 
Bring me the box labeled "thinking cap" ... and then read this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic