[ Pobierz całość w formacie PDF ]
.The following are the methods for the Dateobject:int getDate() returnsthe day of the month.int getDay() returnsthe day of the week, starting with 0for Sunday.int getHours() returnsthe hour between 0 and 23.int getMinutes() returnsminutes.int getMonth() returnsthe month of the year, starting with 0for January.int getSeconds() returnsseconds.int getTime() returnsthe number of milliseconds since January 1, 1970.int getTimezoneOffset()returns the local time zone offset.int getYear() returnsthe year.int parse(sting "Date")returns the number of milliseconds since January 1, 1970.void setDate(int date)sets the day of the month, between 0and 31.void setHours(int hour)sets the hour of the day, between 0and 23.void setMinutes(int minutes)sets the minutes in the hour, between 0and 59.void setMonth(int month)sets the month of the year, between 0and 11.void setSeconds(int seconds)sets the seconds of the hour, between 0and 59.void setTime(int tseconds)sets the time to the passed time value.void setYear(int year)sets the year.string toGMTString()returns the date in GMT string format.string toLocaleString()returns the date to the current location's string format.Date UTC(int year, month, day [,hrs] [, min] [, sec]) converts the passed parametersinto a Date object.The MathObjectThe Math object providesdefined math constants and some math functions.The followingstatic constants are available:E-The number e.LN2-The natural logarithmof 2.LN10-The natural logarithmof 10.LOG2E-The logarithm base2 of 10.LOG10E-The logarithmbase 10 of e.PI-The pi constant.SQRT1_2-The square rootof 1/2.SQRT2-The square rootof 2.The Math object providesthe following mathematical functions:abs is the absolute valuefunction.acos is the arccosinefunction.asin is the arcsine function.atan is the arctangentfunction.ceil is the ceiling function.cos is the cosine function.exp is the exponentialfunction.floor is the floor function.log is the natural logarithmfunction.max is the maximum function.min is the minimum function.pow is the power function.random is a random numbergenerator.round is the roundingfunction.sin is the sine function.sqrt is the square rootfunction.tan is the tangent function.HandlingEventsHandling events in JavaScript allows the script to be informedwhen an event has occurred.In Java, an event is trapped and thendispatched to the code that was intended to handle that event.In JavaScript, when an object is defined in the HTML, the functionused to handle that event is specified with the object.For example,look at the example of placing a button into a document:<INPUT TYPE="button" VALUE="OK"NAME="OKButton"onClick="ValidateMe(this.form)">The top line defines a button with a VALUEof "OK" and a NAMEof "OKButton".The bottom line is what you want to understand here.Notice the onClick parameterto the button.This line is associating the defined function ValidateMewith the onClick event ofthe button.This specifies to the code to handle the event directlyfrom HTML.JavaScript recognizes different event handlers for a number ofsupplied objects.The following are all the supported event handlerswith their associated objects:onBlur-select,text, textareaonChange-select,text, textareaonClick-button,checkbox, radio,linkonFocus-select,text, textareaonLoad-windowonUnload-formonMouseOver-linkonSelect-text,textareaonSubmit-formFor all of these events, the syntax to define the event handleris the same.Inside the object's associated HTML tag is the event'sname followed by the function you want to handle the event.Forexample, the following:<BODY onLoad="sayHello("HelloTo Me")>sets the function sayHelloto the onLoad event of thewindow object.ArraysThe syntax to declare arrays in JavaScript is very different fromJava, primarily due to the loose typing of JavaScript.Arraysare declared without specifying an implicit type; JavaScript resolvesthe type at a later time.For example, to declare a single-dimensionalarray, the syntax would be as follows:var aBunchOfInts = new makearray(50);The syntax to load the array would be like this:ABunchofInts[0] = 1;Due to the dynamic binding property of JavaScript, the type ofthe array is not set until a value is assigned.Operatorsand ExpressionsJavaScript follows the Java framework for operators and expressions.Binary operators are of the form operand1operator operand2.Unary operators are of the formoperator operand1 or operand1operator.Bitwise operators convert operands into32-bit integers before performing the operation.The following are all valid JavaScript operators:+addition-subtraction*multiplication/division%modulus++increment--decrement&&and||or!not==equal to>greater than<less than>=greater than or equal to<=less than or equal to!=not equal to&bitwise AND|bitwise OR^bitwise XOR>>sign-propagating right shift<<left shift>>>zero fill right fillJavaScript supports assignment expressions using =, evaluation expressions, and conditional expressions.Conditionalexpressions take the form (condition)? val1 : val2, where val1is processed if the condition is true;otherwise val2 is processed.StatementsJavaScript provides conditional, loop, object-manipulation, andcomment statements.The syntax for each of the statement typesis identical to Java.The syntaxes for the JavaScript- supportedstatements are as follows:Conditional Statementsif-else:if (condition) { statements1 }[else { statements2}]Loop Statementsfor:for ([initial-expression;] [condition;][increment-expression]) { statements}while:while (condition) { statements}break:breakcontinue:continueObject-Manipulation Statementsfor in:for (variable in object) { statements }new:objectName = new objectType ( param1[,param2].[,paramN] )this:this[.propertyName]with:with (object){ statements}Comment Statements// comment text/* multiple-line comment text */SummaryThe JavaScript language provides enough of a diversity from Javato retain its own identity.A large number of the statements,expressions, and operators are identical.However, the loose typingof JavaScript gives it a flavor all its own.Contactreference@developer.com with questions or comments.Copyright 1998EarthWeb Inc., All rights reserved.PLEASE READ THE.Copyright 1998 Macmillan Computer Publishing.All rights reserved
[ Pobierz całość w formacie PDF ]