Hello all, I am recently feeling that an ability to dereference properties directly from the prototype (an . operator, but which ignores the top level of the prototype chain) could potentially lay the groundwork for great usability improvements in javascript.
I've written a proposal, but am new to the TC39 scene; it has no champion currently. I'd love if anyone could give me feedback, impressions, criticism, etc. on my idea. Thanks!
I wonder if there could still be benefit to the proposed operator? It would allow extensions to Object.prototype on an opt-in basis - e.g. I could opt-in by explicitly defining:
Object.defineProperty(Object.prototype, 'map', { enumerable: false, value: fn => {
const result = {};
for (const k in this) result[k] = fn(this[k]);
return result;
}});
const obj = { a: 1, b: 2, c: 3 };
console.log(obj..map(v => v + 1));
Thanks for pointing out that Object.prototype will never change - at the very least, I should refine the argument in my proposal.
No, no property must ever be added to Object.prototype, and since null objects exist that don't inherit from Object.prototype, it wouldn't be appropriate to do so anyways.