Home  >  Article  >  Web Front-end  >  JavaScript partial functions

JavaScript partial functions

高洛峰
高洛峰Original
2016-11-26 10:10:161084browse

Use closures to create functions with pre-filled certain parameters.
Javascript code

  
 function jionWords(a, b){  
   return [a, b].jion(' ');  
    }  
  
 function prefixer(word){  
   return function(b){  
     return jionWords(word, b);  
   }  
 }  
  
 var hate = prefixer('Hate');  
  
 hate('Java'); //返回值为:Hate Java


It can be seen that you can use this to create a function with a dynamic name. It should look awesome and the code will be more readable.


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn