27.10.2017 02:00

I do think the iPhone X is interesting, but I’m very happy that I ordered the 8 Plus instead because waiting for the X with a broken 6 Plus would have been very annoying. Not to mention how broken most apps will be until developers get a chance to update them.


27.10.2017 02:00

Not enough coffee or not enough sleep this week.


27.10.2017 02:00

My dogs. Luna is the big “Obama dog”, and the little one is Tara.


27.10.2017 02:00

For of is one of a few recent additions to the for loop in Javascript. It makes it possible to do what is basically a foreach in most other programming languages, like for example C#. for(var item of array){} is more or less the same as foreach(var item in array){} in C#. Why not just use .map or .forEach? Well, I usually do, but to do that can be a little bit cumbersome when you are dealing with async methods and async await, because then the arrow function in the .map also needs to be async etc. And it is nice to have an fast way to just loop through an array without having use a old school for loops. They are useful sometimes, and you should know how they work, but it is nice to have a quick and easy way to just loop thorugh an array.


26.10.2017 02:00

Hello World

Old School For loops

26.10.2017 02:00

I assume most of you are either using for of or map instead of the old school for loops these days, right? It is easier. But I think the old school for loop is a work of art. I’m talking about the C style for loop; not the foreach.

```text The way it works, is that the for loop has three elements ```

  • The Initializer(starting point)
  • The condition(continue to run until it becomes false)
  • Increment(do this after each iteration)
  • ```

    ```text It is very easy to reversing it, without reversing the actual array: ```

    ```text And then you have the ‘break’ and ‘continue’ keywords, the former will exit the loop, while continue will go on to the next iteration. It might be easier to use other styles of loops, but I have never found anything I could not do with a classic C style for loop; there are probably some, but I can’t think of any. ```

    What is ‘this’

    25.10.2017 02:00

    All object oreiented programming languages have some kind of variant of ‘this’. It’s called this in C#, and self in Python, Swift and Objective-C.

    ```text This in Javascript and C# is not exactly the same thing. But I think it makes it a little bit easier to understand. In C# this is the "magic" variable you use if you want to access an class variable. ```

    ```text It is a little bit more complicated, but not really, in JavaScript. It simply refers to the current scope. By default this refers to the window object. And each function will per default have their own scope – their own this. Unless you bind a different scope to it, or use call / apply to execute the method with a different scope. ```

    ```text If you for example use the DOM to fetch a node, and run some function like a event handler on that node, you can safely expect ‘this’ in that context to be that node. ```

    ```text You have a few different options to how to deal with ‘this’. Some projects are doing something like ‘var that = this’ or ‘var self = this’. While the correct way to do it is to bind the current context into the method using ‘.bind’. ```

    ```text Neither way is good, the that hack drives me nuts because it’s a horrible hack. And the problem with binding is that it is so fucking slow. ```

    ```text In 2017 I say, bind if you have to, use arrow functions if they solve the problem for you, and always try to use .call or .apply instead of .bind when possible. ```

    Arrow Functions

    24.10.2017 02:00

    We use them all over, not just because they are shorter to write, but also because they look cool, and you don’t need to bind this for them to work with this. I’m going to write about ‘this’ some other time. The biggest difference between a regular function and a arrow function is that the former has it’s own ‘this’, which means that you need to bind to ‘this’, if it needs access to it, while an arrow function on the other hand shares it with it’s parent. You can write an arrow function in three different forms: expression, statements and object litteral.

    ```text A object literal is a way to use the simple form of the expression to make an arrow function return a object. It is this way because the object syntax {} would not work in an expression because that’s the syntax of using a full arrow function. ```

    ```text What to use where? ```

    ```text I use what ever variant that end up with the code that is the easiest to understand. I try really hard to use expression where ever I can. And to use Object Litterals when I need to return objects and to only to use a full function when it is the only way. ```

    Value and reference types

    23.10.2017 02:00

    In my previous post about the .forEach method I said that you can mutate the values of the entities of the array you are running it on. This is only kind of true. You will be able to mutate reference types but not value types. A reference type is: functions, objects and arrays. Values types are: numbers, strings bool etc. The difference is that, when you pass a object to a function you can actually mutate the object, while a number would be passed as a value, and not be mutated. Look at the two examples below: By reference:

    ```text By value: ```


    22.10.2017 02:00

    ```text This have been a tool in my belt for a very long time. Fluid App is the fastest and easiest way to turn a Web Site into a App on OS X. ```

    ```text Why would you do that? ```

    ```text Well, I personally prefer to have som web apps as a separate window outside my browser, because I don’t want it to disappear between all of the way too many tabs I have open, and because some of them are in use all of the time. ```

    ```text It’s only five bucks. And is well worth the money. ```

    ```text I use Fluid, even though I cloud fire up Xcode and do the same thing there. But why would I spend like an hour or something to get it to work right, when I could spend a few minutes doing it in fluid? ```