selfrefactor / rambdax

Extended version of Rambda
https://selfrefactor.github.io/rambdax
MIT License
221 stars 26 forks source link

type returns 'Object' for ES6 shorthand method declarations #32

Closed tidychips closed 5 years ago

tidychips commented 5 years ago

The type function returns 'Object' for ES6 method shorthand when running in an environment where that ES6 isn't transpiled. It's technically correct, but 'Function' seems like it would be more appropriate. This also makes isType and isFunction return unexpected results.

const obj = {
  f(){
    return 4;
  }
};

type(obj.f);  // => 'Object'
typeof obj.f; // => 'function'

It may also be worth considering that it produces the same result for computed property shorthand:

const name = 'f';
const obj = {
  [name](){
    return 4;
  }
};

type(obj.f);  // => 'Object'
typeof obj.f; // => 'function'
selfrefactor commented 5 years ago

I will try to fix that. It is a really nice catch as I haven't thought about such possibility.

selfrefactor commented 5 years ago

Version 2.10.2 should solve this. Thanks again for bringing it up.