javascript design pattern and development practice reading summary

April has passed, and May has come. I can't catch the tail of the spring recruitment, so I can only go to a company for an internship, but in fact, I am very fortunate that I have met a very nice team, although I just went there to familiarize myself with the environment and the environment. Water is water, but I still read the previous projects conscientiously. Of course, I still have to read more books in my spare time. After all, there are still autumn ones after spring recruiting. People still have to work hard! ! ! !

concept:

Closure: In fact, it is to change the life cycle of variables. The recycling mechanism of js is generally garbage collection (of course, bom and dom are a bit different). When the function is called, the local variables are not destroyed, but are still referenced, then this is the closure. .

Higher-order function: As long as any of the following conditions are met, it is a higher-order function

1. Functions can be passed as parameters;

2. Functions can be output as return values.

singleton pattern

 
 
//Singleton mode
var getSingle = function (fn) {

    var result;
    return function(){
        return result || ( result = fn.apply(this,arguments) );
    }

};
//create node
var createLoginLayer = function(){ var div = document.createElement('div'); div.innerHTML = 'I am the login window' ; div.style.display = 'none'; document.body,appendChild(div); return div; };
var createSingleLoginLayer = getSingle (createLoginLayer); document.getElementVById('loginBtn').onclick = function(){ var loginLayer = createSingleLayer(); loginLayer.style.display = 'block'; }

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325116248&siteId=291194637