Lets create a function that will allow us to create dogs, as many dogs as we want, all with different names, types, etc.
First we write an object constructor function:
function dog(name,type,color){
this.name=name;
this.type=type;
this.color=color;
this.bark = function() {
alert(this.name + " lets out a loud bark");
}
}
Now we can call the function to create a dog:
dog1=new dog("spot","dalmation","white with black spots");
And we can use the bark function to make him bark:
dog1.bark();
The full code is:
function dog(name,type,color){
this.name=name;
this.type=type;
this.color=color;
this.bark = function() {
alert(this.name + " lets out a loud bark");
}
}
dog1=new dog("spot","dalmation","white with black spots");
dog1.bark();