Books
in black and white
Main menu
Home About us Share a book
Books
Biology Business Chemistry Computers Culture Economics Fiction Games Guide History Management Mathematical Medicine Mental Fitnes Physics Psychology Scince Sport Technics
Ads

Javascript for dummies. Quick Reference - Vander

Vander Javascript for dummies. Quick Reference - Wiley Publishing, 2002. - 115 p.
Download (direct link): javascriptquickreference2002.pdf
Previous << 1 .. 35 36 37 38 39 40 < 41 > 42 43 44 45 46 47 .. 72 >> Next

Syntax:
dateObjectName.setMinutes(minutesValue)
Example:
averageHeeHawEpisode.setMi nutes(30)
setMonth
The setMonthO method of the Date object enables you to set the month for a specified date. The required monthVal ue parameter can be any integer between 0 and 11, where 0 corresponds to January and 11 corresponds to December. (For any value over 11, the interpreter adds the excess onto the years portion of the date.)
Syntax:
dateObjectName.setMonth(monthVa1ue)
Example:
chri stmas.setMonth(11)
setTimeout
setSeconds
The setSeconds () method of the Date object enables you to set the seconds for a specified date. The required secondsValue parameter can be any integer between 0 and 59. (For any value over 59, the interpreter adds the excess onto the minutes portion of the date.)
Syntax:
dateObjectName.setSeconds(secondsValue)
Example:
pickyDate.setSeconds(12)
setTime
ThesetTimeO method of the D a t e obj ect enables you to set the date and time for a specified date. The required ti meVa 1 ue parameter reflects the number of milliseconds since January 1, 1970 00:00:00. (The fact that no normal human could come up with such a parameter should give you a tip-off that this method is mainly used to assign one date to another, like this: one Date. setTi me(anotherDate. getT i me().)
Syntax:
date0bjectNawe.setTime(time Value)
Example:
husbandAnni versary.setTime(wifeAnni versary.getTime())
setTimeout
Use the setT i meout () method of the frame or wi ndow objects to evaluate an expression after a specified length of time elapses. Using the setTi meout () method is just like setting a timer and then doing something when the timer goes off. (An obvious application for this method is a Web game: You can start the clock ticking when a user begins the game and then pop up a message saying Game Over if the user hasn’t completed the game in a certain amount of time.)
This method takes the following two parameters:
♦ An expression to evaluate
♦ A number that represents the number of milliseconds to wait before evaluating the expression
set\lear
Saving the return value from the setTimeoutC) method in a variable is a really good idea because you need to use this variable if you ever want to cancel the timer. To cancel a timer, you need to pass the variable you saved to the clearTimeoutO method of the frame or wi ndow object (seethe example of cl earTi meout () in the following example for clarification).
Syntax:
timeout ID=setTimeout(exp res si on, number)
Example:
readyYetTimer=setTimeout("alert('5 seconds have elapsed. Are you ready yet?!')", "5000")
clearTi meout(readyYetTi mer)
set\/ear
The s e t Y e a r () method of the Date object enables you set the year for a specified date. The required yearValue parameter must reflect a year between 1970 and 1999. (And because the range is so narrow, you don’t have to specify the 20th century; for example, 1985 and 85 are both perfectly acceptable entries.)
Passing a bogus (out-of-range) value for the yearValue parameter shown in the following example may not cause an immediately obvious error. Because the interpreter assumes that every date falls in the 1900s, any value not between 70 (1970) and 99 (1999) has the effect of setting the date to the last day of 1969. No fireworks, no pop-up warnings — just really goofy date calculations.
Syntax:
dateObjectName.setYear(yearValue)
Example:
nephewGraduati on.setYear(98)
sin
Use the s i n () method of the Math object to return the sine of a number (not the number of sins committed!).
Syntax:
Math.si n(number)
Example:
document.write("Here is the sine of PI: " +
Math . sin(Math.PI))
smatt
Using the smal 1 () method of the Stri ng object enables you display a string in small font (“small” equates to font size 2). See also the f onts i ze () method described earlier in this part.
Syntax:
string.smal 1 ()
Example:
"This is gonna be really teensy.".smal1()
Using the smal 1 () method of the Stri ng object produces the same result as surrounding text with the <SMALL>. . .</SMALL> HTML tag pair.
sort
Use the sort() method of the array object to sort the elements in an array. The sort() method accepts an optional argument that specifies a function name to use for the sorting algorithm. If a function name isn’t supplied, sort О converts the elements in the array to strings (if they’re not already strings) and compares them in lexicographic, or alphabetic, order.
The default sorting algorithm may be sufficient for your needs — unless your array elements contain numbers. But look what happens if your array does contain numeric values: 60, 9, and 100 will be sorted like this — “100”, “60”, “9” — which is probably not what you expected. The following example contains code for a numeric sorting algorithm that, when passed to the sort () method, causes numbers to sort correctly.
Syntax:
arrayName.sort([compareFunction])
Example:
II this sort works just fine for string elements anArray.sort()
Previous << 1 .. 35 36 37 38 39 40 < 41 > 42 43 44 45 46 47 .. 72 >> Next