Lesson 9: Custom JavaScript Objects

Similar documents
PDF SHARE FORMS. Online, Offline, OnDemand. PDF forms and SharePoint are better together

IAT 355 : Lab 01. Web Basics

Object-Oriented Programming Concepts

JavaScript. Training Offer for JavaScript Introduction JavaScript. JavaScript Objects

Microsoft Visual Basic 2005: Reloaded

Basic Object-Oriented Concepts. 5-Oct-17

COMP519 Web Programming Lecture 14: JavaScript (Part 5) Handouts

a Why JavaScript? jonkv interactivity on the web CGI JavaScript Java Applets Netscape LiveScript JavaScript 1: Example

More on JavaScript Functions

Chapter 2 Working with Data Types and Operators

XML JavaScript Object Notation JSON Cookies Miscellaneous What Javascript can t do. OOP Concepts of JS

Web Site Development with HTML/JavaScrip

Lesson 11: JavaScript Libraries

Today. Continue our very basic intro to JavaScript. Lambda calculus

CIW 1D CIW JavaScript Specialist.

Powerful JavaScript OOP concept here and now. CoffeeScript, TypeScript, etc

JAVASCRIPT - OBJECTS OVERVIEW

Creating Custom Dojo Widgets Using WTP

JAVASCRIPT BASICS. JavaScript String Functions. Here is the basic condition you have to follow. If you start a string with

Web Application Development


JavaScript Functions, Objects and Array

JavaScript: Objects, Methods, Prototypes

JavaScript: Sort of a Big Deal,

Java Programming Lecture 7

PEMROGRAMAN BERORIENTASI OBJECT. Indra Gunawan, ST., M.Kom., CEH., CHFI

<script type="text/javascript"> script commands </script>

JavaScript for C# Programmers Kevin

BM214E Object Oriented Programming Lecture 8

CMSC131. Objects: Designing Classes and Creating Instances

5/19/2015. Objectives. JavaScript, Sixth Edition. Introduction to Object-Oriented Programming. Reusing Software Objects

And Even More and More C++ Fundamentals of Computer Science

JAVASCRIPT AND JQUERY: AN INTRODUCTION (WEB PROGRAMMING, X452.1)

Abstract class & Interface

CS 31 Discussion 1A, Week 8. Zengwen Yuan (zyuan [at] cs.ucla.edu) Humanities A65, Friday 10:00 11:50 a.m.

Lecture 18 Tao Wang 1

Chapter 11 Object and Object- Relational Databases

JavaScript CS 4640 Programming Languages for Web Applications

CS111: PROGRAMMING LANGUAGE II

Java: Classes. An instance of a class is an object based on the class. Creation of an instance from a class is called instantiation.

classjs Documentation

Copyright 2016 Ramez Elmasri and Shamkant B. Navathe

Introduction. Introduction

PIC 40A. Lecture 10: JS: Wrapper objects, Input and Output, Control structures, random numbers. Copyright 2011 Jukka Virtanen UCLA 1 04/24/17

Arrays Structured data Arrays What is an array?

Notes on JavaScript (aka ECMAScript) and the DOM

CLASSES AND OBJECTS IN JAVA

Object Oriented JavaScript (Part the Second)

These are activated from the Averiti Control Panel, illustrated in Figure 1. Figure 1: Averiti Control Panel

HTML 5 and CSS 3, Illustrated Complete. Unit L: Programming Web Pages with JavaScript

UNIT -II. Language-History and Versions Introduction JavaScript in Perspective-

& Object-Oriented Programming (POOP) Modified from CS61A Summer 2012 Lecture at UC Berkeley

Classes. Logical method to organise data and functions in a same structure. Also known as abstract data type (ADT).

CSC Web Programming. Introduction to JavaScript

The course is supplemented by numerous hands-on labs that help attendees reinforce their theoretical knowledge of the learned material.

3 The Building Blocks: Data Types, Literals, and Variables

FALL 2017 CS 498RK JAVASCRIPT. Fashionable and Functional!

Remedial classes. G51PRG: Introduction to Programming Second semester Lecture 2. Plan of the lecture. Classes and Objects. Example: Point class

Lecture 3: The Basics of JavaScript. Background. Needs for Programming Capability. Origin of JavaScript. Using Client-side JavaScript

Introduction to Web Tech and Programming

IDM 231. Functions, Objects and Methods

Lecture Contents CS313D: ADVANCED PROGRAMMING LANGUAGE. What is Inheritance?

Instructor s Notes Web Programming JavaScript Functions. Web Programming JavaScript Functions

JavaScript CS 4640 Programming Languages for Web Applications

CS313D: ADVANCED PROGRAMMING LANGUAGE

Factory Method Pattern Creational. » Define an interface for creating an object but lets subclasses decide the specific class to instantiate

BBM 102 Introduction to Programming II Spring Inheritance

CmSc 150 Fundamentals of Computing I. Lesson 28: Introduction to Classes and Objects in Java. 1. Classes and Objects

Derivation of Architecture and Behavior from Static Diagrams, Widely-Accepted Requirements and Design Patterns

Chapter 10 Introduction to Classes

Principles of Programming Languages

Informatik II. Tutorial 6. Mihai Bâce Mihai Bâce. April 5,

The 5 capacities we look for in candidates

MaanavaN.Com CS1203 OBJECT ORIENTED PROGRAMMING DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING

Object-oriented programming

Cpt S 122 Data Structures. Templates

WKA Studio for Beginners

DEMYSTIFYING PROGRAMMING: CHAPTER SIXTEEN ADD AND SEARCH AN ARRAY (TOC DETAILED)

Data Structures and Algorithms in Java. Second Year Software Engineering

I BCS-031 BACHELOR OF COMPUTER APPLICATIONS (BCA) (Revised) Term-End Examination. June, 2015 BCS-031 : PROGRAMMING IN C ++

Classes and Objects. EECS2030 B: Advanced Object Oriented Programming Fall 2018 CHEN-WEI WANG

Introduction to PHP. Handling Html Form With Php. Decisions and loop. Function. String. Array

CS304 Object Oriented Programming Final Term

WINTER. Web Development. Template. PHP Variables and Constants. Lecture

Continuing Education Course #192 Web-Based Programming For Engineers - Part 3

Object Oriented Programming. Assistant Lecture Omar Al Khayat 2 nd Year

CS304- Object Oriented Programming LATEST SOLVED MCQS FROM FINALTERM PAPERS. MC

Objects and Classes. Chapter 8

CHAPTER 6 JAVASCRIPT PART 1

An Introduction To Writing Your Own Classes CSC 123 Fall 2018 Howard Rosenthal

JAVASCRIPT BASICS. Type-Conversion in JavaScript. Type conversion or typecasting is one of the very important concept in

CS111: PROGRAMMING LANGUAGE II

Scala. Introduction. Scala

this Pointer, Constant Functions, Static Data Members, and Static Member Functions this Pointer (11.1) Example of this pointer

Database Assignment 2

CS 2530 INTERMEDIATE COMPUTING

WebBehavior: Consumer Guide

ECE 480 Application Note. By: Jacob Hersha 4/3/15. Creating a Sequence of Media with Visual Studio

Babaria Institute of Technology Computer Science and Engineering Department Practical List of Object Oriented Programming with C

CS304 Object Oriented Programming

Transcription:

Lesson 9: Custom JavaScript Objects

Objectives Create a custom JavaScript object Define properties and methods of custom objects Create new object instances Create client-side arrays using custom objects Create functions and methods for manipulating client-side arrays Use the prototype property

Creating Custom Objects Array objects, custom objects and databases Advantages of custom objects Custom object demonstration

Creating a JavaScript Object: The Constructor Constructor A special function that enables you to create instances of custom objects Defines the properties and methods of your object

Creating an Instance of a Custom Object To instantiate and then populate the properties of each new instance with actual data, you must declare variables The prototype property Used to add new properties or methods to JavaScript objects

Creating Object Methods You can create as many methods for your object as you need (or as many as memory allows) You can make them as simple or as sophisticated as you like

Creating Functions for Your Objects The finditem() function The showall() function Full source code for this client-side array Complex custom objects

Summary Create a custom JavaScript object Define properties and methods of custom objects Create new object instances Create client-side arrays using custom objects Create functions and methods for manipulating client-side arrays Use the prototype property

1. What is a constructor? a. A new instance of a custom object b. A method that defines the properties of a custom object c. A predefined object to which you add methods and properties d. A function that defines methods and properties of a custom object used as a template for instances of the custom object

1. What is a constructor? a. A new instance of a custom object b. A method that defines the properties of a custom object c. A predefined object to which you add methods and properties d. A function that defines methods and properties of a custom object used as a template for instances of the custom object

2. How do you instantiate new instances of an object? a. With the new keyword, the function name, and a list of values b. With the new keyword and the object name c. With the this keyword and the object name d. With the this keyword, the function name, and a list of parameters

2. How do you instantiate new instances of an object? a. With the new keyword, the function name, and a list of values b. With the new keyword and the object name c. With the this keyword and the object name d. With the this keyword, the function name, and a list of parameters

3. How do you access the properties and methods of a newly instantiated object? a. With the this keyword b. By declaring variables c. Using dot notation d. With the new keyword

3. How do you access the properties and methods of a newly instantiated object? a. With the this keyword b. By declaring variables c. Using dot notation d. With the new keyword

4. Define a constructor function for a custom object named empobject. Add three properties: name, age and department. Add one method: showone

4. Define a constructor function for a custom object named empobject. Add three properties: name, age and department. Add one method: showone function empobject(name, age, department) { this.name = name; this.age = age; this.department = department; this.showone = showone; }

5. Using the empobject() constructor function from the previous question, instantiate two new employees in an array named employees.

5. Using the empobject() constructor function from the previous question, instantiate two new employees in an array named employees. var employees = new Array(); employees[0] = new empobject("jane Doe", 25, "Management"); employees[1] = new empobject("jose Ruiz", 35, "Sales");

6. Using the first employee instantiated in the previous question, how would a program access the name and age properties for that object? Output the data to two separate lines on an XHTML page.

6. Using the first employee instantiated in the previous question, how would a program access the name and age properties for that object? Output the data to two separate lines on an XHTML page. document.write("name: " + employees[0].name + "<br />"); document.write("age: " + employees[0].age + "<br />");

7. Using the employees array, write a script block that would output each employee's name while making each name a link to the showone() method. You will define the showone() method in the next question.

7. Using the employees array, write a script block that would output each employee's name while making each name a link to the showone() method. You will define the showone() method in the next question. One way to write this code is as follows: var x = employees.length; for (var j = 0; j < x; j++) { document.write("<a href='javascript:void(employees[" + j + "].showone())'>"); document.write(employees[j].name + "</a><br />"); }