General syntax Pre-alpha versions of Tkhtml Hv3 do not correctly interpret the Function class constructor. Functions group together script code; control structures, operations, method calls, etc.
In this chapter, you'll learn how to: Write your own functions Use homemade functions to improve your code Write functions you can cut and paste into whatever pages you want We'll be using homemade functions in every chapter from now on, so pay extra-close attention to what's going on in this chapter.
Functions as Shortcuts Functions aren't anything new. The alert function, for example, takes whatever text you put inside the parentheses and displays an alert box with that text.
The functions you create act as shorthand as well. Let's say you want to write a link that opens a small window and then centers that window on the screen if the visitor is using Netscape 4.
You could write a link resembling Figure most of the code in it is similar to Figure A link that opens a small window and centers it in Netscape 4 and above-- this won't work in Internet Explorer see note at the end of Chapter 5 However, it is not a good idea to write a link in this way: Furthermore, if you want two or three links on your page, your HTML becomes even uglier and your page's download time increases.
The basic structure of a homemade function A function definition starts with the word function. Naming Your Functions Next comes the function'sname. The rules for naming a function are similar to those for naming a variable. The first character must be a letter; the rest of the characters can include letters, numbers, dashes, and underscores.
Make sure you don't give a function and a variable the same name. Because of this weird behavior, and because function names are case sensitive, it makes sense to have a different convention for naming functions than for naming variables. For variables I use lowercase letters with underscores, and for functions I use what's called in-caps or camel-caps notation.
Names in this notation style consist of strings of words without spaces, in which every word except the first is initial-capitalized, as in openAndCenterTheWindowmyCatand printDate. In-caps notation is a pretty common convention and should serve you well.
Ask Question. up vote 61 down vote favorite.
The write() method is mostly used for testing: If it is used after an HTML document is fully loaded, it will delete all existing HTML. In this example we illustrate what happens when we put rutadeltambor.com() inside a function. When the function is invoked, all HTML.