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
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
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.