Error in keysort.js
olofweb opened this issue · comments
Sorry if my message is off topic because I'm new to Javascript.
I try to use your library (keysort.js). I installed laster npm version (1.0.1) but I get this error :
Uncaught TypeError: Cannot set property 'keysort' of undefined
I see that the last line of keysort.js is :
})(undefined);
If I change this to :
})(this);
I don't get the error.
What is the problem ?
Thank you
Hi,
The IFFE argument this
can be problematic depending on the env, so I've made it browser/node aware.
To explain further, this
doesn't exist if you are requiring the lib inside an arrow function, unless that arrow function is within a class function where a this
does exist for binding; I ran into this a few years ago and modded most of my libs to use a ternary to pass window
or global
in lieu of this
; this was before webpack was a thing.
Thank you for the patch, now it works. And thank you for the explanation :)