Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 Objects In JavaScript. 2 Types of Object in JavaScript Built-in objects User Defined Objects Browser Object Document Object Model.

Similar presentations


Presentation on theme: "1 Objects In JavaScript. 2 Types of Object in JavaScript Built-in objects User Defined Objects Browser Object Document Object Model."— Presentation transcript:

1 1 Objects In JavaScript

2 2 Types of Object in JavaScript Built-in objects User Defined Objects Browser Object Document Object Model

3 3 Built-in Object Provided by JavaScript language Implemented in Browser, if you have a browser, you have built-in object. Ex:  String  Number  Boolean  Array and so on.

4 4 User Defined Object Objects created by Programmer JavaScript provided a built-in object called as Object. You can use Object to create new objects. We will learn more about How to create User Defined Object.

5 5 Browser Object Objects Provided by browser. Allows programmer to access web page functionality Ex: window, document, navigator, history, images[], forms[], anchors[], links[].

6 6 DOM Document Object Model allows us to make dynamic HTML page. Allows us to make dynamic CSS Allows us to modify HTML code dynamically Allows us to modify CSS code dynamically

7 7 DOM Classification DOM Level0 DOM Level1 DOM Level2

8 8 Dom Level 0  Is same as Browser Object (Slide 5)  Ex: window, document, navigator, history, images[], forms[], anchors[], links[]. We did this in the last semester.

9 9 DOM Level 2  Provide access to all elements of a web page using document.all[ ] We will learn more about this later.

10 10 DOM Level 3 Combines features of Level 1 and Level 2. Provides Additional features like  Creating and Modifying CSS dynamically  Creating and Modifying XML dynamically  Provide library to traverse document tree. This is the most important DOM level, we will learn more about this later in the course.

11 11 Type of DOM (W3C) Core DOM HTML DOM CSS DOM Events DOM XML DOM

12 12 Type of DOM (W3C) Core DOM  Presents a marked document as a document tree  Provide library for modifying a marked document dynamically. DOM HTML  DOM that works with HTML  Provide features to modify and create HTML page dynamically.

13 13 Types of DOM (W3C) DOM CSS  Provide library to modify and create CSS dynamically DOM Events  Even Handling using DOM

14 14 Example of Built-in Object JavaScript is an Object Oriented Language. A JavaScript Object has properties and methods  Ex: String JavaScript Object has length property and toUpperCase() method var txt="Hello World!" document.write(txt.length) document.write(txt.toUpperCase())

15 15 JavaScript Built-in Object String Date Array Boolean Math

16 16 User Defined Object Here we will learn  How to Create your own objects. There are 2 ways to create objects  Create a direct instance of object  Create a template ( 본뜨다 ) of an object.

17 17 Create a direct Instance of a JavaScript Object Create an instance of an object and adds four properties to it personObj=new Object() personObj.firstname="John" personObj.lastname="Doe" personObj.age=50 personObj.eyecolor="blue“ Add a method display to the object personObj.display = method1

18 18 Continuation…… Define the method function method1() { document.write(personObj.firstName +”is”+personObj.age old); } For complete code, refer to exercise 2

19 19 Continuation… How to call function of personObj  personObj.display();

20 20 Creating a template of a JavaScript Object This is 2 nd method of creating Object We use a function to define a template of JavaScript Object. function person ( firstname, lastname, age, eyecolor ) { this.firstname=firstname; this.lastname=lastname; this.age=age; this.eyecolor=eyecolor; } The name of object is person

21 21 Create a template of a JavaScript Object To Create an instance of Person, myFather = new Person(“John”, “Doe”, “50”, blue); myMother= new Person(“Sally”, ”Rally”, 45, red); To add a function to an object function person ( firstname, lastname, age, eyecolor ) { this.firstname=firstname; this.lastname=lastname; this.age=age; this.eyecolor=eyecolor; this.function1 = middleName(); }

22 22 Create a Template of a JavaScript Object function middleName (newMiddleName) { this.middleName = newMiddleName; } For complete example, refer to execise 2.2


Download ppt "1 Objects In JavaScript. 2 Types of Object in JavaScript Built-in objects User Defined Objects Browser Object Document Object Model."

Similar presentations


Ads by Google