Work on Core Language Objects Use object Attributes and Methods... The properties variables that define the object and the methods functions that work on the data are included in t
Trang 1The Core language Objects in JavaScript
Session 8
Trang 2A Recap
Scripting Language – Scenarios Language
JavaScript’s Elements
Core JavaScript Object
Client-Side JavaScript Object
Server-Side JavaScript Object
Trang 4 Work on Core Language Objects
Use object Attributes and Methods
Trang 5 The properties (variables) that define the object and the methods (functions) that work
on the data are included in the object
For example, a car is an object The properties of the car are its make, model, and color They have some common methods like,
go (), brake(), reverse()
Trang 6Properties and Methods
To access the properties of the object, we must specify the object name and the property:
objectName.propertyName
To access the methods of an object, we must
specify the object name and the required method:
objectName.method ()
Trang 8Using objects
When creating a Web page we can insert:
Browser objects
Built in script language objects (vary depending
on the scripting language used)
HTML elements
We can also create our own objects for use
in the programs
Trang 9Object Hierarchy
Browser Objects
Script Objects
HTML Elements
Trang 10The this statement
The this statement is more of an internal property
Its value indicates the current object It can have standard properties such as name, length and value applied accordingly
Trang 11The for in statement
The for in statement is used to cycle through each property of an object or each element of an array
The syntax is:
for (variable in object)
{ statements; }
Trang 12The with statement
The with statement is used to execute a set
of statements that have a specified object as the reference
The property is assigned to the object specified in the with statement
The syntax is:
with (object) { statements; }
Trang 13New Operator
The new operator is used to create a new
instance of an object type
The object type may be user-define or built-in
objectName = new objectType (param1
[,param2] [,paramN])
where,
objectName is the name of the new object instance.
ObjectType is a function that defined the type of the object For
example, Array.
Trang 14Eval function
The eval function is used to evaluate a string
of code without reference to any specific
object
The string can be a JavaScript expression,
statement, or a group of statements
The expression can include variables and
properties of an object
var x = 5;
var z = 10;
document.write(eval(“x + z + 5”));
Trang 16Creating String object
There are 3 different methods of creating
Trang 18Math Object
The Math object has properties and
methods that represent advanced
}
Trang 21Date object
The Date object stores dates as the number
of milliseconds since January 1, 1970,
00:00:00
DateObject = new Date(parameters)
Trang 24 One Shot Timer
setTimeout(“javaScript code”, delay)
Timer that Fires at Regular Intervals
setInterval(“javaScript code”, interval)
clearInterval(handler)