Reason for note recording: The popular trend of JavaScript has been unstoppable. The derived AngularJs, Node.js, and BootStrmp have less and less advantages in back-end development for small and medium-sized enterprises. IT is not a position that can rely entirely on experience. IT changes life. As a .Net programmer for three years, I now deeply feel that being conservative is actually fear, avoiding the progress of the times. Life requires passion and motivation!
Text:
1. What do apply().call() and bind() do?
These three are all changed to what this points to in the method
2. What is this?
This refers to the execution object of the method you are currently calling, such as the setTimeout method The output of this
##
1 setTimeout(function(){ 2 console.log(this) 3 },1000)
Window {external: Object, chrome: Object, document: document, Alax: Object, a2: Object…}
var Alax={ name:'Alax', age:27, fuc:function(){ return this.age; } }
The function needs to add () call
Summary: The above calling method can be
console.log((Alax.fuc).call(Alax)) console.log((Alax.fuc).apply(Alax)) console.log((Alax.fuc).bind(Alax)())
Alax={ name:'Alax', age:27, fuc:function(num){ this.age+=num return this.age; } } console.log((Alax.fuc).call(Alax,1)) console.log((Alax.fuc).apply(Alax,[1])) console.log((Alax.fuc).bind(Alax)(1))
The above is the detailed content of This in Js points to the problem of apply().call(),bind(). For more information, please follow other related articles on the PHP Chinese website!