what is fn call

Solutions on MaxInterview for what is fn call by the best coders in the world

showing results for - "what is fn call"
Gregor
24 Oct 2019
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
Pénélope
30 Jul 2017
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