javascript pocket guide [burdette]

Page 123

96

The JavaScript Pocket Guide

lenny instanceof Jedi; false yoda instanceof Person; true yoda instanceof Jedi; true

Since Jedi inherits from Person, yoda is an instance of both data types. Inheritance is the reason why all objects have methods like toString() and hasOwnProperty(). All data types inherit from Object. lenny instanceof Object; true myArray instanceof Object; true

Namespacing Namespacing is a common technique for keeping code separate and reducing naming conflicts. In JavaScript, all you need to do is create objects that store your code and data away from other objects. Often, you name these objects after your Web sites because URLs are guaranteed to be unique. Also, URLs use periods, which look a whole lot like JavaScript dot operators. Many other languages provide special language features to support namespacing. JavaScript lacks these features, but objects are flexible enough to get some of the benefits of namespacing to better organize your code.

note

var PEACHPIT = {}; PEACHPIT.com = {}; PEACHPIT.com.sayHello = function() {


Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.