Avatar of KaranGupta
KaranGupta

asked on 

object constructor

Hi


I was reading an example regarding the object constructor on
"http://www.javascriptkit.com/javatutors/oopjs2.shtml
for practicing the first heading i.e. object constructor and prototyping I have created one small example

 function Animal(name) {            
                    this.speak = function() {
                        alert("Hi " + name);
                    }
                }

                var cat = new Animal("sweetu");
                cat.speak();
which is working fine. But a quick question comes to my mind is what is the practical usage of this concept and if I use it what will be the benefit.

Regards
Karan Gupta
JavaScriptJScriptScripting Languages

Avatar of undefined
Last Comment
darren-w-
Avatar of Kiran Sonawane
Kiran Sonawane
Flag of India image

You can create the number of properties of class "Animal". In above example, class "Animal" has the property speak. In real world scenario, object has multiple properties. You can set the properties of that object using above example
ASKER CERTIFIED SOLUTION
Avatar of darren-w-
darren-w-
Flag of United Kingdom of Great Britain and Northern Ireland image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
JavaScript
JavaScript

JavaScript is a dynamic, object-based language commonly used for client-side scripting in web browsers. Recently, server side JavaScript frameworks have also emerged. JavaScript runs on nearly every operating system and in almost every mainstream web browser.

127K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo