JavaScript continued

This week continued my previous study of JavaScript. I’m finding more resources for this as I go along, and as such have decided to restructure my schedule for the next few weeks.

This week I looked at:

JavaScript: The Good Parts (Selected readings)

This was an interesting read, but unfortunately I feel like a lot of it went over my head at this point. It’s very detailed about the aspects of JavaScript that Crockford finds useful and generally “good” vs. the “awful” ones. A lot of the reasonings are rooted in programming knowledge and experience that I feel like I’m just learning the foundations of; as such I found myself able to follow along with the general threads but not getting as much from the book overall as I had hoped. It certainly seems like a resource that might be interesting to revisit after I have a stronger working knowledge of the language.

That said, it did identify and focus on several of the aspects of the language that I am familiar with from Codecademy’s JavaScript tutorial as being part of the “good” parts, which was nice to see.

Professional JavaScript for Web Developers (Intro & Chapter 1)

Chapter 1 was really interesting and helpful in filling in the blanks of my understanding about the history of JavaScript. It talked about its early versions in Netscape and Internet Explorer, and about the ECMA standards that eventually came into play when developing JavaScript. I also really appreciated how it laid out in very clear terms the differences between the ECMA Standards, the DOM, and the BOM. All of this was sort of muddled in my head before this week.

My understanding of these as of right now:

ECMA Standards: The standards for the syntax, reserved keywords, and general programming language rules upon which JavaScript and other scripting languages can and have been built.

Document Object Model (DOM): The tree hierarchy of HTML files; JavaScript interacts with the DOM, but the DOM is a part of the page and not a part of JavaScript itself.

Browser Object Model (BOM): I’m still trying to distinguish this from the DOM in my head; I know that the BOM is browser-specific and as such doesn’t have the same level of standards that the DOM does. So it’s important to use the core BOM objects that are found cross-browser in order for scripts to be cross-browser friendly.

Beginning JavaScript (Chapter 6)

Chapter 6 looked at the BOM in detail. In particular it provided explanations of the global objects that can be accessed with JavaScript.

  • window (represents the browser window)
    • location
    • history
    • document (represents the HTML page)
      • forms
      • images
      • links
    • navigator
    • screen

The explanation of these (many of which are words I had seen before when working with JavaScript but had not understood within the context of the BOM) was very useful. I find it much easier to understand the language as a whole, and what I am doing in general now that I understand that functions like alert() or prompt() in JavaScript are actually methods of the window object.

This chapter also looked at some useful/interesting methods and properties for the other objects in this tree. In my list below, a word followed by () indicates a method. Otherwise it is a property.

history

  • go() – can be passed a number value (positive or negative) to move backwards or forwards that amount of pages.
  • back() – goes back to the previous loaded page in the browser.
  • forward() – goes forward to the next loaded page in the browser.

location

  • The href, hostname, port, and protocol properties return their respective information about the site being visited. href can also be used to point to another page.

screen

  • height, width, and colorDepth are properties which return their associated values. A later example in the chapter included an exercise to create a page that loads a different background color based on the colorDepth of the user’s browser.

document

  • The document object is where a lot of JavaScript methods and properties live, many of which I have come across already.
  • forms, images, and links – these properties are actually array-like structures called collections, which return all of the objects on a page for their respective type (so all of the images, or all of the links, etc.).
  • write() or writeln() for printing a message to the page.

This chapter also looked at responding to user’s actions with events, which included an introduction/explanation of using onclick to intercept a click and perform an action (such as rotating/changing images).

As I mentioned, I’m finding more and more resources on JavaScript, including the books I’ve looked at this week. I’m really interested in learning more JavaScript, and I think it’s going to be an important area for me to work on in the future. I had originally planned on moving on to jQuery this week, but I ended up opting not to do that yet, because I really want to have a strong foundation and understanding in plain JavaScript before moving on to a library like jQuery. I’m planning on putting together a revised syllabus for the rest of this independent study that reflects some of these new resources and a shifted focus on JavaScript throughout the rest of the semester, while also working on my WordPress theme for eventual completion at the end of July.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.