[ wex-alpha @ 29.03.2013. 17:45 ] @
Imam sljedeci kod: 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.."); } Zanima me objasnjenje sta radi ovaj dio koda: Code: 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? |