In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)05/31 Report--
In this article, the editor introduces in detail "what is the direction of this in js", the content is detailed, the steps are clear, and the details are handled properly. I hope that this article "what is the point of this in js" can help you solve your doubts? let's follow the editor's ideas to learn new knowledge.
Case 1: this points to the global object window in global scope or ordinary function self-execution
Console.log (this.document = document); / / trueconsole.log (this = window); / / truethis.a = 37; / / equivalent to creating a global variable aconsole.log (window.a); / / 37
Case 2: the this inside the event function points to the event source
Function F1 () {return this;} / / in the browser: F1 () = = window; / / in the browser, the global object is window / / in Node: F1 () = = global
Note: if an ordinary function is included in an event function, the internal this still points to window after the ordinary function is executed.
Case 3: when an object method is called, this points to the called object
Let obj = {attr1: 3, func1: function () {console.log (this = = obj) / / output: true console.log (this.attr1) / / output: 3}} obj.func1 ()
Case 4: when a function is called by call or apply, this points to the value of the object passed in
Let obj = {fn: function () {console.log (this);}} obj.fn () / / objobj.fn.call (12); / / 12
Case 5: there is no this,this pointing to the superior this in the arrow function.
Const xiaoming = {name: 'Xiao Ming', say () {/ / this points to the current object console.log (this)}, wait () {setTimeout (()) = > {/ / this points to the current object console.log (this)}, 1000)}} This article "what is the point of this in js" has been introduced. If you want to grasp the knowledge points of this article, you still need to practice and use it. If you want to know more about the article, please follow the industry information channel.
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.