In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly explains the similarities and differences between call and apply in JavaScript. The content of the explanation is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn the similarities and differences between call and apply in JavaScript.
1. Similarities:
A) produce exactly the same effect or effect
B) at least one parameter
C) * parameters must have and be an object (Object), because this is the guy who is lazy.
2. Differences: the way parameters are passed.
Premise:
1. There are two objects: an and B.
2. B has a method (here Function is used instead)
3. B's method (Function) has two ways of parameter transfer, but the result of this method is the same.
One is that except for * parameters, all the other parameters are packaged into an array, that is, B.Function.apply (Arem ARGs).
The other is that all parameters exist separately in their own form (including * parameters), that is, B.Function.call.
4. A wants to have the same method as B, but he doesn't want to build it on his own, that is, he just wants to borrow something ready-made by others (good ).
Specific description:
1. B.Function.call, this example is about An object "calling" B object's Function (a specific method).
Notice the parameter arg in the call method:
A) the number of arg is zero or more
B) arg can be of any type, including Array (I haven't tried it).
Call is translated here as "call", which can be understood in JS as "An object calls a method of B object"
2, B.Function.apply (A _ Function (a specific method).
Notice the parameter args in the call method:
A) args is an instance of an Array object, that is, an array
B) the number of args is zero (that is, it doesn't work) or 1; (whether there can be more than one, need to be confirmed).
Apply is translated here as "apply", that is, "An object applies a method of B object".
Thank you for your reading, the above is "the similarities and differences between call and apply in JavaScript". After the study of this article, I believe you have a deeper understanding of the similarities and differences between call and apply in JavaScript, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.