JavaScript Constructor Function | Constructor Function in JavaScript - JavaScript Tutorial 77

preview_player
Показать описание
Notes for You:: Why JavaScript Constructor Function:
- Object constructor & Object literal notations are convenient for creating single object.
- If you want to create multiple objects of same type, then take help of constructor function.

Case 1) Creating multiple objects of same type using Object constructor & Object literal notations:
- Increase in code redundancy.
- More time consuming.
- Difficult to manage.

Example Code:

var rect1 = {
width:5,
height:5,
getArea:function()
{
},
getPerimeter:function()
{
}
};

var rect2 = {
width:6,
height:6,
getArea:function()
{
},
getPerimeter:function()
{
}
};

var rect3 = {
width:7,
height:7,
getArea:function()
{
},
getPerimeter:function()
{
}
};

Case 2) Creating multiple objects of same type using constructor function:
- Reduces code redundancy.
- Less time consuming.
- Easy to manage.

Example Code:

function Rectangle(width,height)
{
{
};
{
}

}

var rect1 = new Rectangle(5,5);

var rect2 = new Rectangle(6,6);

var rect3 = new Rectangle(7,7);

Note:
- replace < with less-than symbol.
- replace > with greater-than symbol.

=========================================

Follow the link for next video:
JavaScript Tutorial 78 - How to create Objects using Constructor function in JavaScript

Follow the link for previous video:
JavaScript Tutorial 76 - Advantages of Object Literal notation in JavaScript

=========================================

JavaScript Tutorials Playlist:-

=========================================
Watch My Other Useful Tutorials:-

jQuery Tutorials Playlist:-

jQuery UI Tutorials Playlist:-

Bootstrap Tutorials Playlist:-

=========================================

► Subscribe to our YouTube channel:

► Visit our Website:

=========================================
Hash Tags:-
#ChidresTechTutorials #JavaScript #JavaScriptTutorial
Комментарии
Автор

SUBSCRIBE, SHARE & SUPPORT:
VISIT & LEARN AT FREE OF COST:

ChidresTechTutorials
Автор

Nice Explanation. Keep it Up. Here u r Explained about OBJECT CONSTRUCTOR not Constructor function. constructor function is like var obj=new Function(....)

maheshkaturi
Автор

I got stuck with my course and said "Let me look for a tutorial to save me". This one is perfect

Kindly help me with course's slides

saltech