Web Systems Development (CSC-215) Lecture 16: JavaScript – Functions, Objects, Arrays
WSD Makeup Class Friday 27th April 2:00-3:30pm
Javascript also based on objects as already seen with the dom
Defining a Function
Arguments Array Why would you need one?
Arguments Array More concise scripts
Returning values: Cleaning up a full name
Returning an Array
Example Usage
Javascript objects
User Class
Create a new instance
Create empty object and populate
Add property
Accessing Objects
Alternate Syntax
Syntax Variations
arrays
Numeric Arrays
Numeric Arrays - Shorthand
PHP Array Element Assignment
JavaScript Array Element Assignment
JavaScript Array Element Assignment Alternative
Get Array Length
Create, Build & Print Array
Assignment using Array Keyword More elements can be added later on
Associative Array
Multidimensional Arrays
Array functions
concat Banana, Grape, Carrot, Cabbage
concat
join Join array elements to create one string
Push and pop
reverse
sort
For further details, use MDN https://developer.mozilla.org/en-US/docs/Web/JavaScript For further details, use MDN
Practice Exercise Create and demo a JavaScript class named Book Properties Title Author Price Method Getters Setters Update price Use prompt to instantiate two objects as per values entered by the user Print the two Use prompt to ask the user to update the prices Print the two updated objects
Lecture content adapted from chapter 16 of Learning PHP, MySQL, JavaScript, CSS & HTML5.