Home > Web Front-end > JS Tutorial > body text

JavaScript partial functions

高洛峰
Release: 2016-11-26 10:10:16
Original
1122 people have browsed it

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
Copy after login


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.


Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template