Jump to content

Wirral

Members
  • Posts

    4
  • Joined

  • Last visited

Wirral's Achievements

Newbie

Newbie (1/7)

0

Reputation

  1. The chapter begins with a longhand method of creating the star object: var star = {}; star["Polaris"] = new Object; star["Mizar"] = new Object; star["Aldebaran"] = new Object; star["Rigel"] = new Object; star["Castor"] = new Object; star["Albireo"] = new Object; star["Acrux"] = new Object; star["Gemma"] = new Object; star["Procyon"] = new Object; star["Sirius"] = new Object; star["Rigil Kentaurus"] = new Object; star["Deneb"] = new Object; star["Vega"] = new Object; star["Altair"] = new Object; star["Polaris"].constellation = "Ursa Minor"; star["Mizar"].constellation = "Ursa Major"; star["Aldebaran"].constellation = "Taurus"; star["Rigel"].constellation = "Orion"; star["Castor"].constellation = "Gemini"; star["Albireo"].constellation = "Cygnus"; star["Acrux"].constellation = "Crux"; star["Gemma"].constellation = "Corona Borealis"; star["Procyon"].constellation = "Canis Minor"; star["Sirius"].constellation = "Canis Major"; star["Rigil Kentaurus"].constellation = "Centaurus"; star["Deneb"].constellation = "Cygnus"; star["Vega"].constellation = "Lyra"; star["Altair"].constellation = "Aquila"; star["Polaris"].type = "Double/Cepheid"; star["Mizar"].type = "Spectroscopic Binary"; star["Aldebaran"].type = "Irregular Variable"; star["Rigel"].type = "Supergiant with Companion"; star["Castor"].type = "Multiple/Spectroscopic"; star["Albireo"].type = "Double"; star["Acrux"].type = "Double"; star["Gemma"].type = "Eclipsing Binary"; star["Procyon"].type = "Double"; star["Sirius"].type = "Double"; star["Rigil Kentaurus"].type = "Double"; star["Deneb"].type = "Supergiant"; star["Vega"].type = "White Dwarf"; star["Altair"].type = "White Dwarf"; star["Polaris"].spectralClass = "F7"; star["Mizar"].spectralClass = "A1 V"; star["Aldebaran"].spectralClass = "K5 III"; star["Rigel"].spectralClass = "B8 Ia"; star["Castor"].spectralClass = "A1 V"; star["Albireo"].spectralClass = "K3 II"; star["Acrux"].spectralClass = "B1 IV"; star["Gemma"].spectralClass = "A0 V"; star["Procyon"].spectralClass = "F5 IV"; star["Sirius"].spectralClass = "A1 V"; star["Rigil Kentaurus"].spectralClass = "G2 V"; star["Deneb"].spectralClass = "A2 Ia"; star["Vega"].spectralClass = "A0 V"; star["Altair"].spectralClass = "A7 V"; star["Polaris"].mag = 2.0; star["Mizar"].mag = 2.3; star["Aldebaran"].mag = 0.85; star["Rigel"].mag = 0.12; star["Castor"].mag = 1.58; star["Albireo"].mag = 3.1; star["Acrux"].mag = 0.8; star["Gemma"].mag = 2.23; star["Procyon"].mag = 0.38; star["Sirius"].mag = -1.46; star["Rigil Kentaurus"].mag = -0.01; star["Deneb"].mag = 1.25; star["Vega"].mag = 0.03; star["Altair"].mag = 0.77;
  2. Deirdre's Dad, thankyou for that highly illuminating answer. I think I now understand the distinction between star (lowercase) and Star (uppercase). The penny dropped as I read your use of the word 'type'. Perhaps the author avoided the term in case his readers were unfamiliar with it. He does briefly mention prototypes. For interest, I'll type the paragraph: The creation of a class-like interface in this section used the constructor pattern. The constructor pattern is helpful but results in multiple instances of the same method being created each time the object is initiated. A better, but more advanced, way to create multiple objects is to use a prototype pattern. For more information about creating objects using prototypes, see http://msdn.microsoft.com/en-us/magazine/cc163419.aspx I had a quick look at that link but it is not for beginners . Maybe in a year's time
  3. I’m working my way through Javascript Step by Step (Steve Suehring, Microsoft Press) and I’m having difficulty understanding the way the words ‘object’ and ‘property’ are used in the book. In this post I will put verbatim extracts from the book in blue. Things start off simply enough: You can create an object in Javascript in two ways: * Using the new keyword, as shown here: var star = now Object; * Using curly braces, as shown here: var star = {}; The author explains there is no concept of classes in Javascript, but shows how to create objects using pseudo-class constructors: var star = {}; function Star(constell,type,specclass,magnitude) { this.constellation = constell; this.type = type; this.spectralClass = specclass; this.mag = magnitude;} star["Polaris"] = new Star("Ursa Minor","Double/Cepheid","F7",2.0);star["Mizar"] = new Star("Ursa Major","Spectroscopic Binary","A1 V",2.3);star["Aldebaran"] = new Star("Taurus","Irregular Variable","K5 III",0.85);star["Rigel"] = new Star("Orion","Supergiant with Companion","B8 Ia",0.12);star["Castor"] = new Star("Gemini","Multiple/Spectroscopic","A1 V",1.58);star["Albireo"] = new Star("Cygnus","Double","K3 II",3.1);star["Acrux"] = new Star("Crux","Double","B1 IV",0.8);star["Gemma"] = new Star("Corona Borealis","Eclipsing Binary","A0 V",2.23);star["Procyon"] = new Star("Canis Minor","Double","F5 IV",0.38);star["Sirius"] = new Star("Canis Major","Double","A1 V",-1.46);star["Rigil Kentaurus"] = new Star("Centaurus","Double","G2 V",-0.01);star["Deneb"] = new Star("Cygnus","Supergiant","A2 Ia",1.25);star["Vega"] = new Star("Lyra","White Dwarf","A0 V",0.03);star["Altair"] = new Star("Aquila","White Dwarf","A7 V",0.77); The heading he puts on this section is Assembling a star object using a pseudo-class. Note he uses the singular. He doesn’t say ‘Assembling star objects’. The next section is headed Displaying Object Properties and has the following code and explanation: With a for…in loop, you can loop through each of the properties in an object: DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"><html><head><title>Properties</title> <script type="text/javascript"> var star = {}; function Star(constell,type,specclass,magnitude) { this.constellation = constell; this.type = type; this.spectralClass = specclass; this.mag = magnitude; } star["Polaris"] = new Star("Ursa Minor","Double/Cepheid","F7",2.0); star["Mizar"] = new Star("Ursa Major","Spectroscopic Binary","A1 V",2.3); star["Aldebaran"] = new Star("Taurus","Irregular Variable","K5 III",0.85); star["Rigel"] = new Star("Orion","Supergiant with Companion","B8 Ia",0.12); star["Castor"] = new Star("Gemini","Multiple/Spectroscopic","A1 V",1.58); star["Albireo"] = new Star("Cygnus","Double","K3 II",3.1); star["Acrux"] = new Star("Crux","Double","B1 IV",0.8); star["Gemma"] = new Star("Corona Borealis","Eclipsing Binary","A0 V",2.23); star["Procyon"] = new Star("Canis Minor","Double","F5 IV",0.38); star["Sirius"] = new Star("Canis Major","Double","A1 V",-1.46); star["Rigil Kentaurus"] = new Star("Centaurus","Double","G2 V",-0.01); star["Deneb"] = new Star("Cygnus","Supergiant","A2 Ia",1.25); star["Vega"] = new Star("Lyra","White Dwarf","A0 V",0.03); star["Altair"] = new Star("Aquila","White Dwarf","A7 V",0.77); </script></head><body><script type="text/javascript" > for (var propt in star) { alert(propt); } </script></body></html> View this page in a web browser. You are presented with an alert() dialogue box for each of the stars in the star object, for a total of 14. Here’s an example of the type of dialog box you see: (displays alert box with 'Polaris', followed by 13 more alerts, Mizar through to Altair) This step-by-step builds on the earlier example of using pseudo-classes to define properties of objects. In this case, a star object was created with the following code: var star = {}; That object was then given several properties of individual star names by using a call to create a new Star [sic] object (using the pseudo-class): star["Polaris"] = new Star("Ursa Minor","Double/Cepheid","F7",2.0); Each property of the original star object, in this case the name of each star, was then enumerated within the <body> of the code using a for…in loop: for (var propt in star) { alert(propt); } You might be wondering how to get the actual properties of the stars, such as the constellations, magnitudes, types and spectral class. Chapter 14 shows you how to enumerate through each of these. The bits in bold are what trouble me. Here are my questions: 1. When the block of code above is run, how many objects are created in total? 1, 14 or 15? 2. Would it be right or wrong to call the result a collection of objects (in the sense of a Visual Basic collection)? 3. Is the word preceding my [sic] mark a typo for star, seeing that Star is the name of a function, not an object? 4. When the author refers to the named properties of star (constell, type, specclass, magnitude) as it’s ‘actual properties’ (his last para), is he implying that the star name (e.g. Polaris) is not a true property? Hope someone can clear this up so I can get on to the next chapter!
  4. My name is Chris, I'm from Wirral in UK. I have a background in mainframe technologies and Visual Basic. I am teaching myself web languages (Javascript at the moment) and I have joined the forum to get some help with these. My main interests apart from computers are natural history and Creation science.
×
×
  • Create New...