Link to home
Start Free TrialLog in
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
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

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial