Home > Article > Web Front-end > Share an interview question about closures, bind and this
This article mainly introduces you to an interview question about closure bind and this. The article gives detailed sample code. Friends in need can refer to it. Let’s take a look together.
The problem to be solved is to add a click event for each li for the following ul, and pop up the corresponding index
# #Answer 1: bind, point the current anonymous function to this, and pass i as the parameter
var init = function(){ var obj = document.getElementById('text'); for(var i=0;iAnswer 2: Closure
var init = function(){ var lis=document.querySelectorAll("#text li"); for(var i=0;iSolution 3:The stupidest method, matching
var init = function(){ var obj = document.getElementById('text'); for(var i=0;iFor more articles related to sharing an interview question about closure, bind and this, please pay attention to the PHP Chinese website!