1function Product(name, price) {
2 this.name = name;
3 this.price = price;
4}
5
6function Food(name, price) {
7 Product.call(this, name, price);
8 this.category = 'food';
9}
10
11function Toy(name, price) {
12 Product.call(this, name, price);
13 this.category = 'toy';
14}
15
16const cheese = new Food('feta', 5);
17const fun = new Toy('robot', 40);
18
1const animals = [
2 { species: 'Lion', name: 'King' },
3 { species: 'Whale', name: 'Fail' }
4];
5
6for (let i = 0; i < animals.length; i++) {
7 (function(i) {
8 this.print = function() {
9 console.log('#' + i + ' ' + this.species
10 + ': ' + this.name);
11 }
12 this.print();
13 }).call(animals[i], i);
14}
15