Advertisement
vamsiampolu

ES6 is coming,functions will never be the same again

Mar 14th, 2014
198
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var harmonyFunc=s => s;
  2. alert(harmonyFunc(2));
  3.  
  4. var harmonyFunc2=() => 'Welcome to the Matrix,Neo';
  5. alert(harmonyFunc2());
  6.  
  7. //These lyrics found themselves on Mozilla Developer Network from a Maroon5 Song
  8. var a=["We're up all night 'till the sun",
  9.        "We're up all night to get some",
  10.        "We're up all night for good fun",
  11.        "We're up all night to get lucky"
  12.       ];
  13. //defining an anonymous inner function...
  14. var harmonyFunc3=a.map(s=>s.length);
  15. alert(JSON.stringify(harmonyFunc3));
  16.  
  17. var PersonOriginal=function()
  18. {
  19.    this.age=0;
  20.     setInterval(()=>{
  21.         if(this.age<24)
  22.         {
  23.             console.log(age);
  24.             this.age++;//this refers to person
  25.         }
  26.     },1000);
  27.  
  28. }
  29.  
  30. //cannot create constructors using the harmony functional notation
  31. //something to remember when you are creating brand new objects...this
  32. //is because it does not have a sense of this...evil smiley face
  33. var Person=() => {
  34.     this.age=0;
  35.     setInterval(()=>{
  36.         if(this.age<24)
  37.         {
  38.             console.log(age);
  39.             this.age++;//this refers to person
  40.         }
  41.     },1000);
  42. }
  43.  
  44. var p=new Person();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement