JavaScript design pattern and Development Practice reading summary

Source: Internet
Author: User
Tags closure

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.