call() or Function.prototype.call() method calls a function with a given this
value and arguments.
Let’s have a look at an example how to use call()
method:
function Product(name, price) {
this.name = name;
this.price = price;
}
function Food(name, price) {
Product.call(this, name, price);
this.category = 'food';
}
console.log(new Food('cheese', 5).name);
Output: cheese
apply() or Function.prototype.apply() method is similar to call(), the only difference is that the arguments are sent as an array.
call() and apply() are builtin methods on every JavaScript function.
Other builtin methods are:
- Function.prototype.apply()
- Function.prototype.bind()
- Function.prototype.isGenerator()
- Function.prototype.toSource()
- Function.prototype.toString()
Working closely with product teams, designers, engineers and be involved in the full feature creation process in order to ensure that we are keeping highest quality standards by creating automation tools and tests from scratch to successfully deliver a valuable experience for users.