js this points to the problem - this in the context of function execution

this in the context of function executionAs we know from the above, the general calling method is to call the method on the window.How to get this of the current function?1 change this through call/bind/applythis.myName = 'jszhang'; let foo = function() { this.myName = 'zhangsan'; } foo(); console.log(window.myName); // Output what? console.l ...

Added by redmonkey on Wed, 23 Feb 2022 06:07:43 +0200

Analysis of this binding mechanism in Javascript - detailed explanation

Why use this: function identify() { console.log("Hello,I'm " + this.name); } let me = { name: "Kyle" }; let you = { name: "Reader" }; identify.call(me); // Hello,I'm Kyle identify.call(you); // Hello,I'm Reader This simple chestnut can reuse the function identify in different objects without writing a new function for each object. ...

Added by edawg on Mon, 07 Feb 2022 22:37:58 +0200

Talk about call, apply and bind

Q: what are the ways to change this point? Three (I know) call, apply, bind (not including es6 syntax explanation) When I reviewed these methods, I read a lot of blogs and discussions. The first two are well understood, but I took a little time to adapt to the customization of bind! Without much to say, start exploring: ...

Added by gkelley091565 on Sun, 12 Dec 2021 01:52:23 +0200