JavaScript, In My Opinion


#1

A little something I wrote today.

Hope someone finds it useful. Cheers :slight_smile:


#2

On the topic of JavaScript.

This is the one thing (functionality) i’m waiting to see on JavaScript

But the powers that be won’t let it come to life.


#3

When I started learning JS, I avoided classes and “this” because they complicated everything they touched.

Bind is nice if you use classes and this, but I never circled back to learn them well enough to get value from them.

@m.o.o Can you show me how the bind operator would make your programming life easier?


#4

It makes your code cleaner.

If you’ve come across extension functions in Swift, C# or Kotlin its basically the same idea. Simple put extension functions are external functions called on an object as if it were part of the object. Something like this.

class String { }

function revereseFirstWord() {...}

Then you could simple do something like this.

"cool things happen"::reverseFirstWord()
// "looc things happen"

Extension functions are great for when you want to add utility functions like this to a class/object instance and you don’t really want to add it to the class body or in some cases you don’t have access to that class like the String example which is mostly a language level class. Also there’s an entire programming paradigm behind using extension functions to make code cleaner etc.


#5

Please tell me you have a name for this paradigm so I can read up on it.

Or screenshots of before and after the paradigm


#6

The funny thing is that binded functions are even a lot better and more maintainable than extension functions in C#, Kotlin e.t.c. You can read this but mostly the gist is you run into name collisions.

With binded functions you import the function you want and just call it with the syntactic sugar

import { uniq } from 'loadash"
[ 1, 2, 3, 4, 5]::uniq()

With this you can’t run into name collisions

That might be difficult to answer since the functionality doesn’t even exist in JavaScript officially yet. So it probably be useless to you to bother yourself with that But you could google “Protocol Oriented Programming in Swift” but note this is another language entirely and the ideas might not be so easy to port to JS.


#7

On today’s stream I spent a long time trying to debug why my redis client kept disappearing on me.

Turns out internally the code uses classes and this. I did something .apply( null, args ) and it disconnected the redis client method from the handle I had.

Even when I don’t use classes or this, they manage to find a way to screw me over :’(


#8

Hahaha, JS. I’d rather deal with Go’s backwardness than JS’s stupidity. I repented from all the genocides I committed with JS.


#9

Mind confessing to some genocide?