170 likes | 383 Views
OPERATOR - JavaScript. Lesson 2. Working with Objects, Properties and Methods. Objects
E N D
OPERATOR - JavaScript Lesson 2
Working with Objects, Properties and Methods • Objects • JavaScript is an object-oriented programming language, and as such, treats all elements in your HTML document as objects. Each object has a container called window, and inside a window are smaller objects, such as the following:
Methods • Methods are special programming commands associated with object. • Always remember that objects have their own set of methods. • The syntax for writing the object-method function is as follows: object.method() • Each object has its own set of methods. • Methods are also called statements. • A JavaScript code may contain as many methods as necessary.
Properties • Properties are values associated with objects and hold the attributes of objects with the script. • The syntax for assigning property o an object is similar to the syntax for writing methods. • For example, writing document.bgcolor • Document.title
String Objects • A string object can be any text enclosed in quotations. • Example • var txt=“String Object!”; • document.write(txt.length);
Functions and Events • Functions are essential methods that perform operations independent of objects. • Functions are not necessarily associated with objects but provide commands that manipulate objects.
Events • Events occur when visitors interact with certain elements in a Web page. • Are actions taken by your visitors, such as slicking a button, loading a page, or submitting information through an online form. • This interaction sets off a series of events and these events usually occur as functions.
Event Handlers • After you have set up your functions, you can assign them to events in your script. • You need to assign them to event handlers.