Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use call method in JavaScript

Shulou Source: shulou.com Published: 2022-06-03 10:29:30 09月30日 Update

This article is about how to use the call method in JavaScript. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.

1. Call can call this function and modify the direction of the this when the function is running.

2. Through call, the this of the parent type is directed to the this of the child type, so that the child type can inherit the properties of the parent type.

Example

/ / parent constructor function Father (uname, age) {this.name = uname; this.age = age;} / / child constructor function Son (uname, age, score) {Father.call (this, uname, age); this.score = score;} var son = new Son ('ldh', 18,100) Console.log (son): thank you for reading! This is the end of the article on "how to use the call method in JavaScript". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it for more people to see!

Tags: Function type method content point more article good practical instance property article look knowledge reference help related run Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Docker MySQL vpn Shulou Technology macOS