Code:
//Main object
function Pet(name, species, hello) {
this.name = name;
this.species = species;
this.hello = hello;
}
Pet.prototype = {
sayHello: function () {
alert(this.hello + " hello from normal pet");
}
}
//Cat prototype
function Cat(name, hello, breed, whiskerLength) {
Pet.call(this, name, "cat", hello);
this.breed = breed;
this.whiskerLength = whiskerLength;
}
Cat.prototype = new Pet();
Cat.prototype.catNap = function () {
alert(this.name + ": zzzzz...");
}
Cat.prototype.sayHello = function () { //just an overide of Pets sayHello
alert(this.hello + " hello from a cat..");
}
//Main object
function Pet(name, species, hello) {
this.name = name;
this.species = species;
this.hello = hello;
}
Pet.prototype = {
sayHello: function () {
alert(this.hello + " hello from normal pet");
}
}
//Cat prototype
function Cat(name, hello, breed, whiskerLength) {
Pet.call(this, name, "cat", hello);
this.breed = breed;
this.whiskerLength = whiskerLength;
}
Cat.prototype = new Pet();
Cat.prototype.catNap = function () {
alert(this.name + ": zzzzz...");
}
Cat.prototype.sayHello = function () { //just an overide of Pets sayHello
alert(this.hello + " hello from a cat..");
}
Zanima me objasnjenje sta radi ovaj dio koda:
Code:
Pet.call(this, name, "cat", hello);
Pet.call(this, name, "cat", hello);
Koliko sam shvatio, kaze da pri kreiranju prototype, da koristi od Base objekta navedene properije. U ovom slucaju Base objekt je Pet. Dakle koristi name i hello koji su definisani u Pet-u????
Sta predstavlja "cat" u istom kodu?
[IMG]http://img233.imageshack.us/img233/5078/thumbnailte1.th.jpg[/IMG]
They say I look like daddy :D