JSFiddle - React, Tailwind, and code Playground
by fenderistic
JavaScript
function Pet(imageUrl, name, soundUrl) {
this.imageUrl = imageUrl;
this.name = name;
this.soundUrl = soundUrl;
this.talk = function() {
};
}
function Cat(imageUrl, name, soundUrl, favoriteFood) {
Pet.apply(this,arguments);
this.favoriteFood=favoriteFood;
}
Cat.prototype=new Pet();
Cat.prototype.constructor = Cat;
function Dog(imageUrl, name, soundUrl, walkingTime) {
Pet.apply(this,arguments);
this.walkingTime=walkingTime;
}
Dog.prototype=new Pet();
Dog.prototype.constructor = Dog;
var pets=[];
var cat = new Cat('imageUrl','name','soundUrl','favoriteFood');
pets.push(cat);
localStorage.setItem('pets', JSON.stringify(pets));
if (localStorage.getItem('pets') !== null)
{
var pets = JSON.parse(localStorage.getItem('pets'));
}
console.log(pets[0]);