vladislavkopilov

js замыкания

Jul 1st, 2015
310
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //пример 1
  2. function buildCoveTickerMaker( transport ){
  3.   return function ( name ){
  4.     document.write("Here is your transportation ticket via the "+transport+".<br/>"+
  5.     "Welcome to the Closures Cove, "+name+"!");
  6.   }
  7. }
  8. var getSubmarineTicket = buildCoveTickerMaker("submarine"); //запоминаем транспорт
  9. getSubmarineTicket("Vlad"); //выводим
  10. //Here is your transportation ticket via the submarine
  11. //Welcome to the Closures Cove, Vlad!
  12.  
  13. //пример 2
  14. function get2X( x ){ //10
  15.   return function ( y ){ //2
  16.     return x*x*y;
  17.   }
  18. }
  19. var get2XPlus = get2X( 10 ); //запоминаем что x = 10
  20. document.write( get2XPlus( 2 ) ); //выводим 200
Advertisement
Add Comment
Please, Sign In to add comment