Last Modified: 11/9/98![]() |
![]() ![]() ![]() |
|||
|
||||
JavaScript as a Programming Language![]() Credit: Kirk Born (St Sci/NASA)
Elements of JavaScriptWe will explain JavaScript mostly through examples. We assume that you are familar with "C-like" languages and so will not explain those elements of the language that are similar to "C". Client-Side JavaScript:
The main components of JavaScript are:
JavaScript, like many languages, makes a distinction between value versus reference, particulary in terms of copies, comparisons, and arguments. Basically, Booleans and numbers are copied, passed, and compared by value, where as all others (object, array, string, function) are copied, passed, and compared by reference (except strings, which are compared by value) Object Oriented (OO) Programming ConceptsJavaScript is very much an OO type language. The main goals of OO programming are to
// Define the classes---------------- function Student(year,major,..) { ... } function Staff(classification, ...) { ... } function Faculty(tenure, research,...) { ... } ... // Create the objects for these classes - for (i = 0; i < n_Students; i++) { student[i]=new Student(2,"premajor",...) } for (i = 0; i < n_Staff; i++ ) { staff[i]=new Staff("temporary",...) { } for (i = 0; i < n_Faculty; i++) { faculty[i]=new Faculty("tenured",...) { }The parameters you pass to the functions that define the class supply some of the values that define the object. In addition, you may add functions and other variables both to the classes and to individual objects to further describe their behavior. On the other hand, you may decide that, for you specific purposes, staff and faculty should be treated alike, whereas students are to be treated differently. In that case, your division might be FacStaff versus Student. |
![]() |
![]() |
![]() |
|
|
||||
![]() |
![]() ![]() ![]() |