There are four types of objects:
A user-defined object is created much like any other variable, using the var statement. To define it as an object, the programmer adds the "= new Object()" constructor function.
The 'pizza' object can now be used to write a program dealing with various charactistics (variables) pertaining to 'pizza'.
Objects can even have levels of existence, with a property/characteristic being itself an object and forming an heirarchy.
A JavaScript program can be written with all programmer-created variables being primitives. However, the programmer still has to work with objects. Because JavaScript is object-oriented. Remember document.write? It is part of the window object in JavaScript. This is an example of a Browser object. A browser object is not necessarily a part of JavaScript but most browsers support a linkage between JavaScript and the object to allow manipulation of the page.
Built-in objects such as Math, Date, Object, and Array are those associated by JavaScript wioth operations and manipulation of data.
Document objects are accessed using the document sub-object of the Window object. These objects work with the W3C's Document Object Model (DOM) to provide a structured interface with HTML and XML documents and allow manipulation of Cascading Style Sheets. This feature helps with pages utilizing dynamic HTML.
Objects have properties and methods. Properties are a value that can be accessed or changed, like any primitive variable. Properties are accessed by listing the object name followed by a period and the property name. Methods are an action or operation that can be initiated. Using them allows the programmer to control how a web page can be changed and/or the operation of the browser. Methods are accessed similar to properties, but also have trailing parenthesis immediately following the method name. Methods do not have to have all levels of the object heirarchy written to be invoked. Functions are special JavaScript objects that contain executable code, and are created using the function keyword.
|
closed = y/n window closed document = sub-object of window history = sub-object of window location=URL in/to be displayed name=name of displayed page |
alert(str) = displays alert window close() = close current window confirm(str)=displays confirm window open(URL,name,"options")=opens new window prompt(str,str)=displays prompt window |
|
|
if(cont){window.location="nextpage.html";} |
window.alert("Enter number between 0-10"); close(); confirm("Do you wish to continue?"); open("http://www.shawnee.edu","cpage","width=500,height=400"); prompt("Enter your name",""); |
|
alinkColor=color of active links bgColor=color of background fgColor=color of text Form=sub-object of document Image=sub-object of document lastModified=contains date document last changed (unreliable) linkColor=color of unvisited links referrer=URL that linked to page presently displayed (prev page) |
write(str)=writes string to web page |
|
|
document.alinkColor="00ff00"; document.bgColor="00000"; ldate=document.lastModified; (see Methods e.g.) prevPage=document.referrer; |
document.write(ldate); |
|
length=how many documents since cleared |
back()=same as back button on browser forward()=same as forward button on browser go(-num)=cause browser jump back indicated number of addresses |
|
|
pviews=history.length; |
window.history.back(); window.history.forward(); window.history.go(-1); |
|
getDate()=day of month (1-31) getDay()=day of week(1-7) getHours()=hours(0-23) getMinutes()=minutes(0-59) getMonth()=month(1-12) getSeconds()=seconds(0-59) getYear()=year(format:"2005") |
(to print out Mon/Day/Year): var cal=new Date(); document.write(cal.getMonth()); document.write("/"); document.write(cal.getDate()); document.write("/"); document.write(cal.getYear()); |
|
E=Natural log base; PI = value of Pi These to 16 places of accuracy |
abs(num)=absolute value of value in "num" acos(num)=arc cosine of num in radians asin(num)=arc sine of num in radians atan(num)=arc tangent in radians ceil(num)=least integer greater than num cos(num)= cosine in radians floor(num)=greatest integer less than num log(num)=log base e max(n1,n2)=returns whichever is greater of n1 and n2 min(n1,n2)=returns whichever is lesser of n1 and n2 pow(n1,n2)=value of n1 raised to n2 power random()=generates random number between 0 and 1 round(num)=rounds to nearest integer sin(num)=sine in radians sqrt(num)=square root tan(num)=tangent in radians |
|
|
carea=r*r*Math.PI; |
lgst=max(n1,n2); p=pow(n1,n2); where value in n1 raised to n2 power q=random(); puts random decimal number in q amt=round(amt); val=sin(n3); res=sqrt(ab); tan(num)=tangent in radians |
|
isNaN(num)=y/n is value a number parseFloat(str)=convert string to floating decimal number parseInt(str,num)=string->integer, number specifies what number base system(optional) |
if(isNaN(x)) { } x=parseFloat(x); x=parseInt(x); x=parseFloat(x,2) binary |
|