Author Archives: fidar

Psyched about ES6

Making a note of the upcoming features, hopefully I will be able to remember it until it’s actually implemented across all browsers (thumbs up for Mozilla having implemented a lot of it into Firefox already).
 
 
Block scoping & function declarations

   
   function myFn () {

       if(true) {
           var a = 1;
           let b = 2;
           
           function myFn2 () {
              // ...
           }
       }
       
       console.log(a); // 1
       console.log(b); // ReferenceError: b is not defined
       myFn2(); // ReferenceError: fn is not defined
   }  
 

 
 
Constants

    
    const a; // SyntaxError: const declarations must have an initializer
    const a = 1;
    a = 2; // SyntaxError: Assignment to constant variable

    // Note that 'const' variables are block scoped / lexical scoped just as 'let' variables are.
 

 
 
Default parameters


    function myFn (x, y = 2, z = x * 2) {
        return [x, y * x, z];
    }

    myFn(5); // [5, 10, 10]
 

 
 
Destructuring

 
    var [x,y] = [1,2]; // x : 1, y : 2
    [x,y] = [y,x]      // x : 2, y : 1
 

 
 

Multiple return values, spread, rest parameters

   
   function myFn(title, ...vars) {
       return [...vars]; 
   }

   myFn(1,2,3,4,"hoax"); // [2,3,4, "hoax"]
 

   function myFn2(a,b,c) {
       return [a,b,c];
   }

   myFn2(1, ,3); // [1,3]
   

   function myFn3() {
       return [1,2,3];
   }

   var [a, ,c] = myFn3(); // a : 1, c : 3
  

   function myFn4(a,b,c) {
       return b;
   }

   var arr = [1,2,3];
   
   myFn4(...arr); // 2
   

 
 
Collections

  
   var mySet = new Set();
   mySet.add("Hollah");
   mySet.has("Hollah"); // true
   mySet.delete("Hollah");
   mySet.has("Hollah"); // false

   var myMap = new Map();
   myMap.set("Item", 5);
   myMap.set("Horse", "Pinto");
   myMap.get("Item");

   for( var [thing, value] of myMap ) {
        console.log(thing + ": " + value);
   }

   myMap.delete("Item");
   myMap.has("Item"); // false   
  

 
 
Modules

  
   // helpers.js

   export fnA() {
     console.log("fnA!");
   }

   export fnB() {
     console.log("fnB!");
   }
  
  
   // main.js

   import { fnA, fnB } from 'helpers';

   fnA();
   fnB();
  

 
 
Array comprehension

   
   var temp = [ 0, 37, 100 ];
   [t + 273 for (t of temp)]; // [273, 310, 373]

   // Excellent "Cluedo" example from TutsPlus..
   
   var suspects = ["Miss Scarlet", "Colonel Mustard"],
       weapons = ["Candlestick", "Dagger"],
       rooms = ["Kitchen", "Ballroom"];
 
   [(console.log(s + " with a " + w + " in the " + r)) for (s of suspects) for (w of weapons) for (r of rooms)];

   // Miss Scarlet with a CandleStick in the Kitchen
   // Miss Scarlet with a Candle Stick in the Ballroom
   // Miss Scarlet with a Dagger in the Kitchen
   // ...


Music on my mind

I bought an insanely expensive piece of software a couple of weeks ago, it’s intended for making music and I am now trying to learn how to use it properly. As insanely expensive as it might be, it’s equal parts complicated and so it will take quite some time to figure out just the basics, let alone more advanced stuff. But it’s great fun and an awesome outlet for creative bouts, I feel like I’ve found my “thing” and I can’t picture myself ever growing tired of it.. I have melodies and lyrics pouring out of my brain constantly wether I want it or not, and so I guess that I might as well go with the flow on this one, especially seeing as I really enjoy it. Now, if I could only learn how to sing as well. Heh.
Wish me luck on it, I’ve got a feeling that I might need it.

Attached is a short clip, a draft of a song I am currently making. Be warned, it’s trance-ish.

“Why do you keep saying these things,
that you do not mean?
You’re hurting everyone you love,
and now you’re hurting me.

It’s like you can’t hold back when
things wont go your way
But if you can’t turn this around..
Don’t count on me to stay”

Three thoughts on the dozen.

I’ve got three thoughts to pass on to the universe today, out of which one is an honest question. Do not worry, it’s not a long read. All is well.

Just as we all have the capacity to hate furiously, regardless of circumstance and beyond all reason.. so do we also have the capacity for love, as grand and unconditional as life itself. It’s a mere choice of focus and perspective.

The mightiest weapon against violence and war is to see in every stranger’s face not a potential enemy, but a potential friend.

Logically and practically – how can people be allowed to starve in a world of endless abundance? How can the mere idea or thought of it even exist in a system bound by no other limits than those we set ourselves? How can it be in the interest of anybody to own more than they can possibly consume and enjoy? What logical reason could there be to hoard resources you cannot and never will use, when it means other people will have to lead horrible lives because of it? What is the motivation? I cannot wrap my mind around this, I cannot understand. It simply does not compute.

New pens..

2013-10-25-17.06

On my initiative, we’ve just got new pens @ work, thanks to my boss. Fun stuff!

I tried them out but realized that you’d need a certain type of paper for them to blend nicely.. I have no clue what kind, I’ve tried 3 kinds of inking paper from Letraset and neither of them works :/

Uhm-brella

uhmbrellaI’m still working on that “learning Illustrator” thing.. enter Uhm-brella!

(Please steal this idea, I need a good raincoat.)

Random letters

Absent-minded scribblings from a piece of paper, turned digital as I figured I might as well learn Illustrator.

S   V   o  ou   P   K L   M   G  E   c   a

b