Closed andreypopp closed 9 years ago
Same for Reflect
so babel will add local polyfill but target browsers could be Symbol-ready. so we loose in performance and module size in that case
Why use the symbol at all?
Just change:
return {
configurable: true, // must be true or we could not be changing it
get() {
if (!this.hasOwnProperty(_key)) {
this[_key] = fn.bind(this);
}
return this[_key];
}
};
to
return {
configurable: true, // must be true or we could not be changing it
get() {
var fn = this[key].bind(this);
Object.defineProperty(this, key, {
configurable: true,
writable: true,
value: fn
});
return fn;
}
};
The current way is slower too since the overhead of the getter is going to be there every single time, regardless of your use of the private bound method.
@sebmck you are right, that's actually how it was implemented initially https://github.com/andreypopp/autobind-decorator/commit/fb29744229f06bec8575e089f7c5fe28a407c6e5#diff-1fdf421c05c1140f6d71444ea2b27638
The best would be to have babel to transpile Symbol itself.