April has passed, May has come, Spring recruit tail can't grasp, can only go to a company internship, but in fact very fortunate is, met very nice team, although just started to go there is just familiar with the environment and water, but I still diligently to see the project before, of course, spare time or to read more books, After all, the spring has been the autumn strokes Ah, people still have to work harder AH!!!
Concept:
Closure: In fact, is to change the life cycle of variables, JS recycling mechanism is generally garbage collection (of course, BOM and Dom is a bit different), when the call function after the local variables are not destroyed, but still referenced, then this is the closure.
Higher order functions: higher-order functions as long as any one of the following conditions is met
1, functions can be passed as parameters;
2, function can be output as return value.
Single-Case mode
1 //single-case mode2 varGetsingle =function(FN) {3 4 varresult;5 return function(){6 returnResult | | (Result = Fn.apply ( This, arguments));7 }8 9 };Ten One A //Create a node - varCreateloginlayer =function(){ - the vardiv = document.createelement (' div '); -div.innerhtml = ' I am logged in to the floating window '; -Div.style.display = ' None '; - Document.body,appendchild (div); + returnDiv; - + }; A at - varCreatesingleloginlayer =Getsingle (createloginlayer); -Document.getelementvbyid (' loginbtn '). onclick =function(){ - varLoginlayer =Createsinglelayer (); -LoginLayer.style.display = ' block '; -}
View Code
Policy mode
1 varStrategies = {2"S":function(Salary) {3 returnSalary * 4 ;4 },5"A":function(Salary) {6 returnSalary * 3 ;7 },8"B":function(Salary) {9 returnSalary * 2 ;Ten } One } A varCaculatebonus =function(level, salary) { - returnstrategies[level] (salary); - } theConsole.log (Caculatebonus (' S ', 2000));
View Code
JavaScript design pattern and Development Practice reading summary