In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-14 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article is about how to use bind 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.
The bind method in javascript is used to create a new function, which uses the syntax "function.bind (thisArg [, arg1 [, arg2 [,...]), where the parameter thisArg represents the value passed to the target function as a this parameter when the bound function is called.
This article operating environment: windows7 system, javascript1.8.5 version, Dell G3 computer.
What is the use of bind in javascript?
Function.prototype.bind ()
The bind () method creates a new function, and when bind () is called, the this of the new function is specified as the first argument to bind (), and the remaining parameters are used as arguments to the new function for use when called.
Grammar
Function.bind (thisArg [, arg1 [, arg2 [,...])
Parameter thisArg:
The value passed to the target function as a this parameter when the binding function is called. If the binding function is constructed using the new operator, this value is ignored. When you use bind to create a function in setTimeout (provided as a callback), any raw values passed as thisArg are converted to object. If the argument list of the bind function is empty, or if the thisArg is null or undefined, the this of the execution scope is considered the thisArg of the new function.
Parameters arg1, arg2,...:
A parameter that is preset into the parameter list of the binding function when the target function is called.
Return value:
Returns a copy of the original function with the specified this value and initial parameters.
Description:
The bind () function creates a new binding function (bound function,BF). A binding function is an exotic function object (a term in ECMAScript 2015) that wraps the original function object. Calling a bound function usually results in the execution of the wrapper function.
The binding function has the following internal properties:
[[BoundTargetFunction]]-wrapped function object
[[BoundThis]]-the value that is always passed as the this value when the wrapper function is called.
[[BoundArguments]]-list, any call to the wrapper function fills the parameter list with list elements first.
[[Call]]-executes the code associated with this object. Called through a function call expression. The arguments to the internal method are a th value and a list of parameters passed to the function through the calling expression.
When the binding function is called, it calls the internal method [[Call]] on [[BoundTargetFunction]], like this Call (boundThis, args). Where boundThis is [[BoundThis]] and args is [[BoundArguments]] plus a list of parameters passed in through a function call.
The binding function can also be constructed using the new operator, which behaves as if the target function has been built. The supplied this value is ignored, but the prefix is still provided to the mock function.
Thank you for reading! This is the end of the article on "how to use bind 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!
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: 274
*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.