WritingJournal ArticlesI have written articles for software training journals and newsletters, both print and online. Below is an excerpt of an article I wrote for ZD Journals and ZDNet.
employee.add("Fred Smith");
This is somewhat more terse and self-explanatory than: employee[employee.length + 1] = "Fred Smith"; Another (perhaps more important) benefit of objects is that they're self-contained or encapsulated. This makes for code that is both easy to re-use and to share. An object defines a data structure (data members, fields, or properties) and functions (methods) that manipulate that data structure. When programmers use an object, they do not need to know how its methods were programmed. They simply need to know what the methods are named and what arguments they expect to receive. For example, you've probably already used the Window object's alert() method to display a simple message box. To use this method, you simply need to know that the alert() method exists, and that it accepts one argument (the message that it will display). You don't need to know how JavaScript's developers wrote the alert() method to be able to use it. Training materialsI have developed more than 40 courses for Logical Operations, Ziff-Davis Publishing, and Element K. Some of these consisted of student and instructor training manuals (and supporting media, like PowerPoint slides, data files, and Director interactives), while others were Web-based self-study tutorials, or instructor-led distance learning. Here are some examples of text taken from courses I have written: Attenuation
The electronic signals that are used to transmit data through a network are prone to attenuation--a loss of signal strength or quality. The greater the distance that signals must travel, the greater the attenuation that they experience. You might think of water streaming out of a garden hose as an analogy. Water sprays out of the end of the hose with a certain amount of force, which enables the water to stream through the air. As the water travels away from the hose, gravity and friction attenuate the force of the stream, and eventually there is not enough concentrated force to keep the water in the air. By amplifying or regenerating a signal, you can extend the distance that a signal can travel. Introduction to the Cookie Object When JavaScript code creates variables and objects,
they exist in memory only as long as the Web page that created them is
still loaded. As soon as you move to another page, the browser performs
garbage collection and removes them from memory. If you want to carry
a value across pages, you need to have a way to set the value aside for
later retrieval. A common way to do this is to store the value in a cookie. Methods In JavaScript, methods are functions that are stored
as a property of an object. For example, the employee object
that you considered earlier might have methods such as changeSalary( ),
transfer( ), or fire( ). It makes sense to include these functions as
members of an employee object because they are things that you might do
to an employee. It would not make sense to apply these functions to objects
such as cubicles, debits, or fleetVehicles.
For example, you might fire an employee, but it is unlikely that you would
try to fire a cubicle. By encapsulating a particular method within an
object, you provide a logical way to associate functions with the data
on which they operate.
The Employee_changeSalary function will be a method
of the Employee object. In line 11 of the Employee constructor function,
the Employee_changeSalary function is assigned to the changeSalary property.
In methods, as with constructor functions, the this keyword refers
to the object itself. Notice that neither the method name (this.changeSalary)
nor the function reference (Employee_changeSalary) is followed by parentheses.
When JavaScript encounters a function name followed by parentheses, it
attempts to run that function. When assigning a property to a method name,
you do not want to call the function; you want to refer to the function
itself.
Then you could change the employee's salary as follows. employeex.changesalary (); The rules for naming methods are the same as those for any function. However, you might find it beneficial to use a naming scheme like the one used for Employee_changeSalary. This approach helps to identify this function as a method, rather than just another run-of-the-mill function. In this scheme, the first part of the function name (before the underscore character) identifies the object to which the method belongs, and the second part identifies the purpose of the function. It is a good habit to make the second half of the function name identical to the name you assign to the property that holds the method. Typically, you assign a function to an object property within a constructor function. However, you could make the assignment outside of the constructor, and you could even assign a new method to predefined objects, such as Window. Distance learningI have developed distance learning courseware that are used by a variety of customers, including Ziff-Davis University, Element K, SmartPlanet, Barnes & Noble University, the U.S. Navy Manufacturing Technology (MANTECH) Program, U.S. Army Medical Department (AMEDD). Click the link below to view writing samples from a Web-based distance learning course that I developed. |