You can already do that - `function f() {} Object.setPrototypeOf(f,
customObject)`On Thu, Jan 10, 2019 at 4:18 PM Matthew Robb <[email protected]> wrote: > Fwiw I'd absolutely love a way to create function objects that inherit > from an existing custom object. > > On Thu, Jan 10, 2019, 2:13 PM Sultan <[email protected] wrote: > >> >what're the benefits over a object indexed by numbers `const o = >> Object.create(null); o[0] = 12; ...`? >> >> Better "optimisable" heuristics in a similar vain to `TypedArrays`. Most >> engines have perf cliffs with indexed objects after a certain threshold, >> >> Memory: at some point indexed objects have to grow by some factor(* N of >> the current size) until it reaches and exceeds your desired size resulting >> in more memory use that you bargained for or at some point the engine could >> downgrade it to dictionary-mode for any one reason. >> >> It is a fickle round to cross when you want predictable throughput >> performance, TypedArrays afford this, but they are not generic(support any >> value). >> >> >About the other function proposal (`Function.create`) I don't see any >> benefits in day to day use having a function without prototype >> >> Both the Array.create and Function.create are not meant as day-to-day >> data-structures. >> They are meant as low-level building blocks for abstraction that might be >> used on a day-to-day, abstractions that wish to guarantee better >> predictable performance. >> >> >and there'd be no way to get the length or iterate over it if you did. >> >> You don't need a length property to iterate the array if you own and >> manage the data-strucure: >> >> Exhibit A: >> var len = 10 >> var arr = Array.create(null, len) >> for (var i = 0; i < len; i++) arr[i] >> >> Exhibit B: (tuple) >> >> var arr = Array.create(null, 2) >> arr[0] = 'a' >> arr[1] = 'b' >> return a >> >> In both examples you don't need a length property to access/visit all the >> elements in the array given they are both statically known at creation time. >> >> >> On Fri, Jan 11, 2019 at 12:20 AM Jordan Harband <[email protected]> wrote: >> >>> Sorry if I was unclear; it's *impossible* to have an array without a >>> `.length` own property, and there'd be no way to get the length or iterate >>> over it if you did. I'm also not clear on why you'd want to store named >>> properties on an array, especially if you can't iterate it because it >>> doesn't have a length? >>> >>> On Thu, Jan 10, 2019 at 11:04 AM T.J. Crowder < >>> [email protected]> wrote: >>> >>>> On Thu, Jan 10, 2019 at 1:54 PM Augusto Moura >>>> <[email protected]> wrote: >>>> > >>>> > If you don't want the iterable features neither the own properties, >>>> > what're the benefits over a object indexed by numbers `const o = >>>> > Object.create(null); o[0] = 12; ...`? >>>> >>>> Exactly. >>>> >>>> And re functions, using them as state containers without their usual >>>> features seems like a bad idea^H^H^H^H^H^H^H^H edge case best handled >>>> by `setPrototypeOf` and `delete`. :-) >>>> >>>> -- T.J. Crowder >>>> _______________________________________________ >>>> es-discuss mailing list >>>> [email protected] >>>> https://mail.mozilla.org/listinfo/es-discuss >>>> >>> _______________________________________________ >>> es-discuss mailing list >>> [email protected] >>> https://mail.mozilla.org/listinfo/es-discuss >>> >> _______________________________________________ >> es-discuss mailing list >> [email protected] >> https://mail.mozilla.org/listinfo/es-discuss >> >
_______________________________________________ es-discuss mailing list [email protected] https://mail.mozilla.org/listinfo/es-discuss

