Which four cases cannot use this
1, between rows, 2, set of one layer, 3, timer; 4, binding
The value used to set this
<!DOCTYPE HTML><HTMLLang= "en"><Head> <MetaCharSet= "UTF-8"> <title>Title</title></Head><Body></Body></HTML><Scripttype= "Text/javascript"> functionShow (A, b) {Console.log ("this is"+ This+", A is"+a+", B is"+b); } Show (1,2);//window //the parameters in call can be multiple, the first is this, and the following parameters are listed down //Show.call (this, parameter)Show.call ( A,1,2);// A //The role of call is similar to apply, but it only has two parameters, the first is this, the second is an array //show.apply (this,[parameter]);show.apply ( A,[1,2]);// //The difference between call and apply is only in the method of parameter passing. </Script>
Where to use:
functionmyaddevent (obj, SEv, fn) {//To sum up is://attachevent--compatible: IE7, IE8, not compatible with Firefox, Chrome, IE9, IE10, IE11, Safari, opera//addeventlistener--compatible: Firefox, Chrome, IE, Safari, Opera; incompatible IE7, IE8 if(obj.attachevent) {obj.attachevent (' On ' +sev,function() {fn.call (obj);//If you do not need to call,this point is window, use call to ensure that this point to the current obj }); } Else{obj.addeventlistener (SEv, FN,false);//to bind an element to an event, a function }}
Call and apply