IS 337: Website Administration

Lecture for December 3: Basic JavaScript and Prototype

+
-

Topics

Commit to Your Library!

  • The library is more powerful than plain JavaScript.
  • The library is (probably) safer than plain JavaScript.
  • The library (probably) "breaks" some JavaScript (e.g., for...in loop).

JavaScript Is Very Object-Oriented! (And Prototype Makes It More So)

  • Numbers!!!! toggle
    • parseInt('42', 11).toString(9)
    • (2).sqrt.toFixed(4)
    • (-8).abs()
    • n.times(function)
  • Strings toggle
    • str.strip()
    • str.stripScripts()
    • str.stripTags()
  • Arrays toggle
    • array.clear()
    • array.join(connector)
    • array.flatten()
    • array.each(function)

Dollar-Sign Functions

  • Searching for elements toggle
    • $('some_id') searches DOM for element with id="some_id"
    • $$('css selector') searches DOM for elements that match the CSS selector toggle
      • Supports almost the whole CSS 3 standard!
    • $F(field) returns the value of the specified field (actual element or id)

Readings and Resources

Creative © 2007 Calvin College and Jeremy D. Frens.
This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 United States License.