Advertisement
MUstar

Javascript ES6 Example - Arrows

Jul 27th, 2018
376
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //ES6 Arrows Example.
  2.  
  3. let evens = [0,2,4,6,8,10,12,14,16,18,20];
  4. let odds = evens.map(v => v + 1);
  5. let nums = evens.map((v,i) => v + i);
  6. let pairs = evens.map(v => ({even: v , odd : v + 1}));
  7. document.write(odds + '<br/>');
  8. document.write(nums + '<br/>');
  9. document.write(JSON.stringify(pairs) + '<br/>');
  10.  
  11. let fives = [];
  12. nums.forEach(v => {
  13.     if(v % 5 === 0){
  14.         fives.push(v);
  15.     }
  16. });
  17. document.write(JSON.stringify(fives) + '<br/>');
  18.  
  19. let eat_talk = {
  20.     name : "최나나",
  21.     word : ['라면','빵','냉면'],
  22.     print_wrap(){
  23.         this.word.forEach( f =>
  24.             document.write(this.name + '는 '+ f + '를 먹었다.<br/> ')
  25.         );
  26. //          this.word.forEach(function(f){
  27. //                  document.write(this.name + '는 '+ f + '를 먹었다.<br/> ')
  28. //              }
  29. //          );
  30.     }
  31.  
  32.  
  33.  
  34.  
  35. };
  36. eat_talk.print_wrap();
  37.  
  38.  
  39. let lets_play_dog = {
  40.     pet : "댕댕이",
  41.     eat: ['사료','간식','풀을 뜯고'],
  42.     play : ['수영' , '산책' , '쟁반던지기'],
  43.     print_eat(){
  44.         this.eat.forEach( e => document.write(this.pet + '가 ' + e + ' 먹고있다.<br/> ')
  45.         );
  46.     },
  47.     print_play(){
  48.         this.play.forEach( p => document.write('난 오늘 ' + this.pet + '와 ' + p + '를 했다. <br/>'))
  49.     }
  50. };
  51.  
  52. lets_play_dog.print_eat();
  53. lets_play_dog.print_play();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement