www.pickatutorial.com Computer Tutorials
Top eBooks: C/C++ | C# | Android | Mathematics | Database | Cloud | Graphics | Networking | Oracle | Hardware | AI
Top Tutorials: C/C++ | C#.NET | PHP MySQL | Java | Java Script | jQuery | HTML | xHTML | HTML5 | VB Script| CSS
Lessons JavaScript Objects and Classes 3 Bookmark and Share
Tutorial Home
Lesson 1
Lesson 2
Lesson 3
Lesson 4
Lesson 5
Lesson 6
Lesson 7
Lesson 8
Lesson 9
Lesson 10
Lesson 11
Lesson 12
Lesson 13
Lesson 14
Lesson 15
Lesson 16
Lesson 17
Lesson 18
Lesson 19
Lesson 20
Lesson 21
Lesson 22
Lesson 23
Lesson 24
Lesson 25
Lesson 26
Lesson 27
Lesson 28
Lesson 29
Lesson 30
Lesson 31
Lesson 32
Lesson 33
Lesson 34
Lesson 35
Lesson 36
Lesson 37
Lesson 38
Lesson 39
Lesson 40
Lesson 41
Lesson 42
Lesson 43
Lesson 44
Lesson 45
Lesson 46
Lesson 47
Lesson 48
Lesson 49
We will continue our discussion of objects in this lesson too. In the last lesson we learned ways to create our own objects in JavaScript. In this lesson we will explore the ways to add methods and properties to our JavaScript objects.

We can add new properties to an existing object by simply assigning it a value.

Assuming that the objStudent already exists and we want to add the property name to it. This can be achieved by the following line of code:

objStudent.name="Danial";

Functions are actions we perform on object data. Functions are defined within the constructor function of an object. Recall the definition of the student object from the previous lesson. In the following code we define a function inside the constructor function of the student:

function student(firstname, age, course)
{
this.firstname=firstname;
this.age=age;
this.course=course;

this.updateCourse=updateCourse;
function updateCourse(course)
{
this.course=course;
}
}

The updateCourse() function assigns the value of the course argument to the student's course property.


Next >>> Lesson No. 21: JavaScript for...in Loop





Home - Advertise - Contact - Disclaimer - About Us
© Since 2006 pickatutorial.com -- All Rights Reserved.