What grinds my gears in JS

32 views
Skip to first unread message

Youness Belfkih

unread,
Mar 26, 2016, 2:10:35 AM3/26/16
to Strengthen JS
Arithmetic operations shouldn't accept Objects

useful for game developers

`NaN === NaN` shouldn't return false

again useful for game developers

=== is `Object`

ES6 Object.is usefull but i hate how long it is
if (!Object.is) {
  Object.is = function(x, y) {
    // SameValue algorithm
    if (x === y) { // Steps 1-5, 7-10
      // Steps 6.b-6.e: +0 != -0
      return x !== 0 || 1 / x === 1 / y;
    } else {
      // Step 6.a: NaN == NaN
      return x !== x && y !== y;
    }
  };
}

Choose one null value either `null` or `undefined`

DOM and UserLand use `null` to mean a null value while JavaScript uses `undefined` mostly to mean null, in strict and sloppy mode you can do `val == null` or `val != undefined`, but in strong mode you cant, I well aware that i can use default and rest parameters but i'm thinking beyond parameters, i'm thinking about unifying code APIs and undefined not being a keyword

valueOf()

i was going to say no more valueOf but i guess you already did that

its never used except for Date 
we have `Date.now()` now but most `Date.now` polyfills i saw use +Date.now its just one line of code so no worries
Reply all
Reply to author
Forward
0 new messages