Learning the front end also has a period of time, but the effect is very tiny. The use of time is not sufficient, although the use of work to learn. But that doesn't make me an excuse.
Today I studied (actually watched many times) call apply method.
functionABC (A, b) {returnA +b;}functioncall1 (num1,num2) {returnAbc.call ( This, num1,num2);//The call method passes a parameter in one pass}functionapply1 (num1,num2) {returnAbc.apply ( This, [num1,num2]);//here the Appl method passes the arguments that need to be an array, in the indeterminate pass //The amount of time to pass the arguments is very convenient. }//Action (1): Calling functionCall1 (10,20);// -Apply1 (10,20);// -//Action (2): Extended scopeWindow.color = ' Red ';//color = ' Red ' is also possible, but with window opening is better for understanding//define an Obj objectvarobj ={color:' Blue '}varObj2 ={color:' Green '}functionSaycolor () {Console.log ( This. color);} Saycolor.call ( This);//' red '//in non-strict mode This===windowSaycolor.call (window);//' Red 'Saycolor.apply ( This);//' Red 'saycolor.apply (window);//' red '//without the second parameter, the call,apply uses no differenceSaycolor.call (obj);//' Blue 'Saycolor.apply (obj);//' Blue '//call,apply can do a good job of decouplingSaycolor.call (OBJ2);//' Green 'Saycolor.apply (OBJ2);//' Green '//(3) in the use of constructor inheritance, to inherit propertiesfunctionM (x, y) { This. x =x; This. y =y; return This. x + This. Y;}functionMchild (a,b,c) {M.call ( This, A, b); This. C =C;}varM1 =NewMchild (10,20,30); Console.log (m1.x); //TenConsole.log (M1.Y);// -Console.log (m1.c);// -
JavaScript Learning Note (1)) —————— Call,apply method