# Dereference from Prototype Only

**URL:** <https://es.discourse.group/t/dereference-from-prototype-only/2275>\
**Category:** 💡 Ideas\
**Tags:** proposal\
**Created:** [January 11, 2025, 8:37pm UTC](https://es.discourse.group/t/dereference-from-prototype-only/2275 "2025-01-11T20:37:00Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gershy](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/gershy/32/2350_2.png) [@Gershy](https://es.discourse.group/u/Gershy)\
**Post date:** [January 11, 2025, 8:37pm UTC](https://es.discourse.group/t/dereference-from-prototype-only/2275/1 "2025-01-11T20:37:00Z")

</div>

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.

Example:

```javascript
const obj = { a: 1 };
console.log(obj..a); // undefined
console.log(obj..toString); // [Function: toString]

```

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!

[Gershy/proposal-dereference-prototype-only](https://github.com/Gershy/proposal-dereference-prototype-only)

---

<div class="post-metadata">

**Author:** ![aclaymore](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/aclaymore/32/501_2.png) [@aclaymore](https://es.discourse.group/u/aclaymore)\
**Post date:** [January 11, 2025, 9:38pm UTC](https://es.discourse.group/t/dereference-from-prototype-only/2275/2 "2025-01-11T21:38:11Z")

</div>

Welcome @Gershy!

> " We unfortunately see `{}.hasOwnProperty.call(myObject, ...)` used instead"

`Object.hasOwn` was added to avoid needed to do this: [Object.hasOwn() - JavaScript | MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/hasOwn)

> "I believe Javascript would benefit greatly from utility methods available on `Object.prototype` ."

I can not see TC39 ever adding new properties to `Object.prototype`, the chance of breaking existing code is too high. [GitHub - tc39/faq](https://github.com/tc39/faq#why-dont-we-just-break-the-web)

---

<div class="post-metadata">

**Author:** ![Gershy](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/gershy/32/2350_2.png) [@Gershy](https://es.discourse.group/u/Gershy)\
**Post date:** [January 11, 2025, 10:22pm UTC](https://es.discourse.group/t/dereference-from-prototype-only/2275/3 "2025-01-11T22:22:00Z")

</div>

Hello @aclaymore, 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:

```javascript
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.

---

<div class="post-metadata">

**Author:** ![ljharb](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/ljharb/32/8_2.png) [@ljharb](https://es.discourse.group/u/ljharb)\
**Post date:** [January 12, 2025, 12:19am UTC](https://es.discourse.group/t/dereference-from-prototype-only/2275/4 "2025-01-12T00:19:45Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![aclaymore](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/aclaymore/32/501_2.png) [@aclaymore](https://es.discourse.group/u/aclaymore)\
**Post date:** [January 12, 2025, 9:07am UTC](https://es.discourse.group/t/dereference-from-prototype-only/2275/5 "2025-01-12T09:07:13Z")

</div>

To get a method-chaining like flow for plain objects I think [GitHub - tc39/proposal-pipeline-operator: A proposal for adding a useful pipe operator to JavaScript.](https://github.com/tc39/proposal-pipeline-operator) would be the way to achieve this because it doesn't require globally modifying `Object.prototype`, instead the functions are imported only where used. This reduces 'spooky action at a distance' and makes dead-code-elimination analysis easier.
