Re: Beforeunload for PWA

2021-03-30 Thread Jordan Harband
PWAs and events aren't part of the JS language; see https://html.spec.whatwg.org On Tue, Mar 30, 2021 at 5:39 AM Adam Eisenreich wrote: > I think that PWA should have the ability to override the default > beforeunloadEvent message. > > Since returning string is already deprecated and removed

Re: Since JSDoc seems cerebrally dead...

2020-11-11 Thread Jordan Harband
gt; >> > html += "function " + name + " " + signature.trim() >> + "\n"; >> >> > html += "\n" + comment + "\n\n"; >> >> > html += "\n"; >> >> >

Re: Why does Object.keys return an Array instead of a Set?

2020-10-18 Thread Jordan Harband
`new Set(Object.keys(obj))` seems pretty straightforward - I doubt it's worth adding something to the language just to make that shorter. Separately, if you're looking for a deduped O(1) lookup of key presence, you already have _an object_ - `Object.prototype.hasOwnProperty.call(obj, key)`. On

Re: Why does Object.keys return an Array instead of a Set?

2020-10-17 Thread Jordan Harband
Because Object.keys was standardized in 2009, 6 years before Set existed. On Fri, Oct 16, 2020 at 6:51 PM #!/JoePea wrote: > Sets are faster, even for tiny lists of four items. See the perf tests > (tested in Chrome): > > https://twitter.com/trusktr/status/1315848017535098880 > >

Re: Since JSDoc seems cerebrally dead...

2020-10-12 Thread Jordan Harband
Hopefully (imo) people are hand-writing more docs now, rather than relying on autogenerated prose. On Mon, Oct 12, 2020 at 1:23 PM #!/JoePea wrote: > Why not? People are generating less docs now? That doesn't sound good! > > #!/JoePea > > On Mon, Aug 17, 2020 at 4:15 PM Isiah Meadows > wrote:

Re: [PROPOSAL] Provide a way to enforce integrity check on module imports

2020-08-01 Thread Jordan Harband
That seems like something that could possibly be achieved via https://github.com/tc39/proposal-import-assertions On Sat, Aug 1, 2020 at 1:15 AM Michaël Rouges wrote: > Hi all, > > As proposed a year ago on an old repository (thanks to ljharb, noticed me > that fact), on the browser side, the

Re: Why does a JavaScript class getter for a private field fail using a Proxy?

2020-07-27 Thread Jordan Harband
ea > > On Wed, Jul 15, 2020 at 10:47 PM Jordan Harband wrote: > > > > So can: > > ```jsx > > const o = { foo() { if (o.foo !== this) { throw 'detected'; } } }; > > o.foo(); // works > > new Proxy(o, {}).foo(); // throws > > ``` > > >

Re: Why does a JavaScript class getter for a private field fail using a Proxy?

2020-07-15 Thread Jordan Harband
So can: ```jsx const o = { foo() { if (o.foo !== this) { throw 'detected'; } } }; o.foo(); // works new Proxy(o, {}).foo(); // throws ``` (as would a class that used a closed-over WeakMap for each "private field") Private fields do not introduce any new hazards here. On Tue, Jul 14, 2020 at

Re: Allow for async/await to use global.Promise and not builtin Promise

2020-05-06 Thread Jordan Harband
You already do have that right; you can use any Promise implementation you choose, or none at all. You do *not*, however, typically have the "right" to alter what syntax does, and `async`/`await` explicitly chose that philosophy. On Tue, May 5, 2020 at 11:37 PM medikoo wrote: > J

Re: Allow for async/await to use global.Promise and not builtin Promise

2020-05-06 Thread Jordan Harband
Anything "more efficient" would likely not be spec compliant, which would break code relying on those guarantees. Overriding any builtin is a bad practice for well over a decade, and I'm not sure why doing so would be desirable. "Fast" doesn't matter if correctness is not assured. On Tue, May 5,

Re: Object.safeAssign

2020-05-01 Thread Jordan Harband
I'm confused about that as well; there were a spate of CVEs about it a year or two ago (2 or 3 of my libraries were "affected"), but just like the minimist/mkdirp ones, they were only actually vulnerabilities for a minority of the use cases. Have there been any recent vulnerabilities you're aware

Re: Why can't the left-hand side of an assignment expression use optional chaining?

2020-04-30 Thread Jordan Harband
See https://github.com/tc39/proposal-optional-chaining/issues/18 On Thu, Apr 30, 2020 at 1:08 PM #!/JoePea wrote: > I was hoping to avoid things like > > ```js > const baz = this.foo?.bar?.baz > if (baz) baz.lorem = 123 > ``` > > #!/JoePea > > On Thu, Apr 30, 2020 at 1:04 PM #!/JoePea wrote: >

Re: Promise.allSettled() - why string?

2020-04-17 Thread Jordan Harband
The iteration protocol has a boolean data property `.done` - I don't know if anyone ever suggested some kind of `isDone()` method for that, and I think the iteration protocol sets a precedent of the "tag" on the object being a primitive. On Fri, Apr 17, 2020 at 7:25 PM Felipe Gasper wrote: >

Re: Conditional assign operator

2020-04-13 Thread Jordan Harband
Are you familiar with https://github.com/tc39/proposal-logical-assignment/ ? On Mon, Apr 13, 2020 at 2:17 AM Sultan wrote: > The following would assign to the address foo in obj if and only if it has > not already been assigned. > > var obj = {} > var foo = Math.random() > obj[foo] ?= 1 > > The

Re: Promises: unhandled rejections and finally()

2020-03-28 Thread Jordan Harband
It does pass through the fulfillment status - but it does that by adding both an onFulfilled and an onRejected handler, so it does affect the "unhandled rejection" hook. On Sat, Mar 28, 2020 at 7:23 PM Felipe Gasper wrote: > Hi Logan, > > Thank you .. that makes sense. I’m not sure why now but

Re: syntax for case ranges

2020-02-19 Thread Jordan Harband
@kdex (sorry i missed this; your message was in my spam folder) if you find a way that Annex E is non-exhaustive, please file an issue on the spec - I would like it to be exhaustive. On Mon, Feb 3, 2020 at 11:16 AM Naveen Chawla wrote: > Thanks! Although I think it is a value judgement about

Re: [Proposal] Optional spreading

2020-02-15 Thread Jordan Harband
> somehow. > > On Sat, Feb 15, 2020 at 10:05 AM Jordan Harband wrote: > >> Since object spread already ignores nullish values, a syntax change would >> only be needed for array spread. Then, the two kinds of spread would >> support different syntactic features, which seems incons

Re: [Proposal] Optional spreading

2020-02-15 Thread Jordan Harband
Since object spread already ignores nullish values, a syntax change would only be needed for array spread. Then, the two kinds of spread would support different syntactic features, which seems inconsistent. On Sat, Feb 15, 2020 at 7:56 AM Beknar Askarov wrote: > Thank you, everyone, for

Re: Double wildcard "re-exports"... off-limits forever?

2020-02-13 Thread Jordan Harband
Wouldn't the solution be, don't use `import * as`, but instead, explicitly import and re-export what you want? On Thu, Feb 13, 2020 at 8:02 PM Ben Wiley wrote: > Apologies if this has already been talked about at length at some point. I > was unable to find much in the way of relevant

Re: Any chance for an `Object.assignProperties` ?

2020-02-13 Thread Jordan Harband
fineProperties( > base, > mixins.reduce( > (descriptors, mixin) => assign( > descriptors, > getOwnPropertyDescriptors(mixin) > ), > {} > ) > ); > ``` > > On Thu, Feb 13, 2020 at 6:51 PM Jordan Harband wrote: > >> `Ob

Re: Any chance for an `Object.assignProperties` ?

2020-02-13 Thread Jordan Harband
`Object.defineProperties(target, Object.getOwnPropertyDescriptors(source))`? On Thu, Feb 13, 2020 at 2:24 AM Andrea Giammarchi < andrea.giammar...@gmail.com> wrote: > Both `Object.assign` and `{...extend}` suffer a tiny gotcha: properties > are never assigned, neither retrieved, as accessors,

Re: Yet another attempt at typed JS data

2020-02-11 Thread Jordan Harband
ome better primitive, as in `const Shape = > Object.defineShape(...)` and `Object.createShape(Shape)` or similar. > > On Sun, Feb 9, 2020 at 10:01 PM Jordan Harband wrote: > >> That already exists - `Array.from({ length: 4 }, () => whatever)` - I >> assume that the hope is to have

Re: Yet another attempt at typed JS data

2020-02-09 Thread Jordan Harband
That already exists - `Array.from({ length: 4 }, () => whatever)` - I assume that the hope is to have an array where it is *impossible* for it to have the wrong "kind" of data, and a userland factory function wouldn't provide that. On Sun, Feb 9, 2020 at 10:39 AM kai zhu wrote: > > It's a bit

Re: Array.prototype.toggle

2020-02-07 Thread Jordan Harband
I would not be interested in adding any more mutating methods to Array.prototype, ever. I'd suggest using `.filter` for this. On Fri, Feb 7, 2020 at 5:29 AM manuelbarzi wrote: > many things that already provide array could be polyfilled, and probably > many were polyfills before. it's not about

Re: Yet another attempt at typed JS data

2020-02-07 Thread Jordan Harband
the "type" in Typed Arrays refers to the bit size in memory; being able to pass an arbitrary value seems like it would require implementations to calculate the precise (not just the maximum) memory size a single item requires. On Fri, Feb 7, 2020 at 6:33 AM Andrea Giammarchi <

Re: Proposal: `await.all {...}` for parallelism

2019-11-19 Thread Jordan Harband
If we have `await.all`, what about `await.race`, `await.allSettled`, `await.any`? On Tue, Nov 19, 2019 at 7:45 PM Jacob Bloom wrote: > To simplify the problem of working with promises in parallel, I > propose this new syntax: > > ```javascript > async function initialize() { > let foo, bar,

Re: Array.prototype.sort( callbackfn [ , thisArg ] )

2019-11-11 Thread Jordan Harband
Michaël Rouges wrote: > For example, to easily sort the values, compared with another list, using > only one iteration. > > Le mar. 12 nov. 2019 à 07:42, Jordan Harband a écrit : > >> I'd assume it's because sort predates ES5, when the thisArg was added; >> and

Re: Array.prototype.sort( callbackfn [ , thisArg ] )

2019-11-11 Thread Jordan Harband
I'd assume it's because sort predates ES5, when the thisArg was added; and also because a well-behaved comparator only operates based on `a` and `b` - why would you need a receiver? On Mon, Nov 11, 2019 at 7:34 PM Michaël Rouges wrote: > Hi all, > > Is there a reason to not have a `thisArg `

Re: Template literal property names in object literals

2019-11-07 Thread Jordan Harband
wouldn't seem to present daunting implementation issues. > But maybe this last assertion is incorrect and ambiguities would arise or > implementation would be a nightmare? > > Thanks > > -- > Alex Kodat > Senior Product Architect > Rocket Software > t: +1 781 684 229

Re: Template literal propery names in object literals

2019-11-07 Thread Jordan Harband
Anything dynamic - computed - should be in brackets, since that's what that indicates. Thus, template literals with substitutions must require brackets. Based on sentiments like https://github.com/tc39/ecma262/issues/1399#issuecomment-452910799, either all template literals or none should be

Re: Optional Curly Braces in JavaScript

2019-11-02 Thread Jordan Harband
for this specific reason, as it's easy to write for all > types of people. > > Thank you all, > -- > *From:* es-discuss on behalf of kai zhu < > kaizhu...@gmail.com> > *Sent:* Saturday, November 2, 2019 8:06:50 PM > *To:* Jordan Harband &g

Re: Optional Curly Braces in JavaScript

2019-11-02 Thread Jordan Harband
My preference would be to make them required in the places they're currently optional :-) Optional curly braces have led to many bugs, not just in JS (the "goto fail" SSL bug, for example) - why is this risk worth making it easier to write code on a whiteboard, where it doesn't need to be valid

Re: Re: Modify Promise.all() to accept an Object as a parameter

2019-10-11 Thread Jordan Harband
The current API accepts an *iterable*, which means any object that has `Symbol.iterator`, such as an array or a Set. Throwing when it receives a non-iterable object is an important tool to catch bugs. If Promise.all was made to accept a non-iterable object as well, I suspect many bugs would go

Re: Why globalThis instead of something intuitive like globalObject, systemGlobal, or globalEntity?

2019-09-21 Thread Jordan Harband
This question is more appropriate for the proposal repo, in which a very lengthy naming document will hopefully answer all of your questions: https://github.com/tc39/proposal-global/blob/master/NAMING.md Please address all further comments or replies on this topic to the proposal repo. Thanks!

Re: Use hashes as keys instead of toString() for values like object, function to index objects

2019-09-08 Thread Jordan Harband
By default, the behavior would have to remain the same, or else it would break the web. See https://esdiscuss.org/topic/object-id-hash-etc for more on hash codes. On Sun, Sep 8, 2019 at 4:36 AM Tadas Lapė wrote: > The problem > > Javascript allows to index objects not only with strings,

Re: Symbols and SymbolAt

2019-09-08 Thread Jordan Harband
There's already `.codePointAt`, and `[...str].length`. The thing that's really needed more than code points is grapheme clusters; see https://esdiscuss.org/topic/working-with-grapheme-clusters On Sun, Sep 8, 2019 at 5:01 AM Dimitrian Nine wrote: > Maybe i don't know something, but want to

Re: [Proposal] Refer to actual value : keyword "itself"

2019-09-06 Thread Jordan Harband
`var itself = 3;` means that your choice of keyword wouldn't be an option; you'd be limited to something that was currently a syntax error. On Fri, Sep 6, 2019 at 2:53 AM Cyril Auburtin wrote: > also optional-chaining will help > ```js > return { > ...state, > child: { >

Re: Optional chaining syntax but with the "mice" operator ?

2019-09-06 Thread Jordan Harband
Syntactically marking, in a chain, what you'd like the final value of the chain to be, seems interesting - forcing optionality into it seems unnecessary, though, if such a syntactic marker could be attached to all forms of property access. Something like: `a.b>.c.d` or `a?.b>?.c?.d` or

Re: [Proposal] Optional spreading

2019-08-22 Thread Jordan Harband
Since you can do this now with: ```js [ 1, ...(condition ? [2, 3] : []), 3, ] ``` and object spreading already handles this for you, is extra syntax really needed? On Thu, Aug 22, 2019 at 6:52 PM Scott Rudiger wrote: > I like it; code seems cleaner to me with its use. However, since the

Re: Array.prototype.joinWith(iterable)

2019-08-16 Thread Jordan Harband
Can you elaborate a bit more on how this is a *common* case in the wider ecosystem? On Fri, Aug 16, 2019 at 5:29 AM Andrea Giammarchi < andrea.giammar...@gmail.com> wrote: > early reply "which otehr cases"? this is just an example: > > [2019, 08, 16, 14, 28, 30].map(i => i < 10 ? ('0' + i)

Re: Array.prototype.findIndex(fn, startIndex = 0)

2019-08-15 Thread Jordan Harband
I believe every array iteration method that takes a callback, except for reduce and reduceRight, take an optional receiver as the last argument (the `this` value), so they can't be meaningfully/ergonomically extended. On Thu, Aug 15, 2019 at 3:00 PM Andrea Giammarchi <

Re: Modulo Operator %%

2019-08-15 Thread Jordan Harband
Static functions don't have the same risk as prototype functions; `Math.mod` would make sense to add. One suggestion, though, would be to try to add the API method first, and look at usage for awhile before trying to add the syntax. On Thu, Aug 15, 2019 at 10:12 AM Andrea Giammarchi <

Re: Promise resolution handler fires before synchronous constructor stack has finished.

2019-07-28 Thread Jordan Harband
No, that's not accurate - every `.then` always executes on a future tick, never synchronously. On Sat, Jul 27, 2019 at 11:11 PM Ranando King wrote: > Isn't it always the case that `Promise.resolve()` returns an immediately > resolved Promise? That means that the `.then` clause would get

Re: Promise resolution handler fires before synchronous constructor stack has finished.

2019-07-28 Thread Jordan Harband
When I run this in a node repl, that's exactly what happens - perhaps your simplified example has simplified out the bug? On Sat, Jul 27, 2019 at 6:57 PM #!/JoePea wrote: > I feel like I'm going crazy, but I have a class hierarchy, and one of > the constructors in the hierarchy defers some

Re: Proposal: Typeof Trap

2019-07-28 Thread Jordan Harband
t; You can see examples of this on comp.lang.javascript, and through a search > engine by looking for "return document.all" or "return document.layers". > There are also some legacy books showing the practice. > > /Michael > > > -Original Message- &g

Re: Proposal: Typeof Trap

2019-07-27 Thread Jordan Harband
e able to supplant `instanceof` > without losing any of its reliability. Just a thought... > > On Sat, Jul 27, 2019 at 3:57 PM Jordan Harband wrote: > >> With something that while unintuitive in one case, is eternally robust >> and reliable. >> >> If you want exte

Re: Proposal: Typeof Trap

2019-07-27 Thread Jordan Harband
ogonal, where does that leave you? > > > > [1] <https://twitter.com/BrendanEich/status/798317702775324672> > > > > *From:* Jordan Harband > *Sent:* Saturday, July 27, 2019 3:00 PM > *To:* Michael Haufe > *Cc:* ViliusCreator ; es-discuss@mozilla.org > *S

Re: Lazy Iterators

2019-07-27 Thread Jordan Harband
See https://github.com/tc39/proposal-iterator-helpers On Sat, Jul 27, 2019 at 1:45 PM Artem Kobzar wrote: > The proposal based on really worst thing in JavaScript Arrays. > > If i as developer want to make declarative code with combination of > `Array#map`, `Array#filter` or `Array#reduce` - i

Re: Proposal: Typeof Trap

2019-07-27 Thread Jordan Harband
Those two PRs are about removing implementation-defined behavior from `typeof`, making it *more* reliable - there is no trend away from using and relying on `typeof`, full stop. `Symbol.hasInstance` is a part of why `instanceof` is actually unreliable - because user code can hook into it. It

Re: Proposal: SuperSet

2019-07-09 Thread Jordan Harband
Are you perhaps looking for https://github.com/tc39/proposal-set-methods ? On Tue, Jul 9, 2019 at 1:18 PM Oğuz Kılıç wrote: > Yes, I already consider it as an enriched version of the current set > method, I just like calling it superset :) > > On Tue, Jul 9, 2019 at 11:05 PM Григорий Карелин >

Re: effect of editor/ide on javascript programming-style

2019-06-28 Thread Jordan Harband
As much as I like vim, this seems like more of an argument against using vim than anything for the language - also it's not "usually" just 1 frontend developer; altho that may be your experience. I often like to say it's *never* just one - even if it's you, it's also "you in 6 months", and that

Re: `String.prototype.trimStart`/`String.prototype.trimEnd` with a given string

2019-06-24 Thread Jordan Harband
;> No idea how common of a use case this is; I personally ran across it >>> when reviewing the source code for marked (specifically the [rtrim >>> method]). That example only does characters, not strings, but it's used in >>> the wild by a package with ~2m weekly downloads

Re: `String.prototype.trimStart`/`String.prototype.trimEnd` with a given string

2019-06-23 Thread Jordan Harband
`trimStart` and `trimEnd` are better-named versions of the very very long-existing `trimLeft` and `trimRight`, which lack this ability, along with ES5's `trim`. It wouldn't make sense for these three to differ. It certainly seems like a potential language proposal to add a string argument to all

Re: Re: What do you think about a C# 6 like nameof() expression for

2019-06-16 Thread Jordan Harband
again, `Object.keys({ y })[0]` will give you the string `y`, and will survive refactoring tools. you can even do `function nameof(obj) { return Object.keys(obj)[0]; }` and then `nameof({ y })`. Obviously it's slightly less ergonomic than `nameof y` would be - but adding new syntax is very

Re: Re: What do you think about a C# 6 like nameof() expression for

2019-06-14 Thread Jordan Harband
`nameof whatever` → `Object.keys({ whatever })[0]`, but I'm a bit confused why it'd be better to type `nameof foo` in code, rather than `'foo'` - if you change `foo` to `bar`, you have to change both of them anyways. On Fri, Jun 14, 2019 at 1:31 PM guest271314 wrote: > Am neither for nor

Re: Proposal: native XML object support.

2019-05-15 Thread Jordan Harband
(that's not react's creator; that's redux's creator, who is now a member of the react core team) On Wed, May 15, 2019 at 8:17 PM Isiah Meadows wrote: > Fun fact: React elements are plain JS objects that are nearly > JSON-compatible. The only reason why they aren't is because of the presence >

Re: Proposal: Lazy Error.message

2019-05-11 Thread Jordan Harband
It can already be a getter if you like, which would allow a function to compute the value on demand. On Sat, May 11, 2019 at 6:55 AM _ zaoqi wrote: > Allow Error.prototype.message to be a Function > > It is useful in this case: > > https://github.com/browserify/commonjs-assert/pull/47 > >

Re: Discussion: Module Reflection - import.reflect

2019-04-24 Thread Jordan Harband
`import * as Self from '.'` should work in every implementation of ESM that's shipped so far that I'm aware of. On Wed, Apr 24, 2019 at 8:39 AM Randy Buchholz wrote: > Maybe my example was misleading by using an `import`. What I’m talking > about is inspecting the module from within itself.

Re: Proposal for Promise.prototype.flatten

2019-04-24 Thread Jordan Harband
Would this not work? async function test(promise1, promise2, promise3) { const val1 = await promise1.catch(); // ignore exceptions const [val2, val3] = [] = await Promise.all([promise2, promise3]).catch(); await Promise.all([promise1, promise2, promise3]); // throw to caller return val1

Re: Proposal: Static Typing

2019-04-05 Thread Jordan Harband
`const` means it can't be reassigned, but a non-frozen value can still have its properties changed or its [[Prototype]] changed (including Promise, which could have its `.then` method changed), which would change the type. On Fri, Apr 5, 2019 at 11:36 AM guest271314 wrote: > Two possible

Re: Destructuring for Array-like objects

2019-03-19 Thread Jordan Harband
`const [a, b] = Array.from(anyArraylikeObject);` On Tue, Mar 19, 2019 at 7:22 PM Frederick Stark wrote: > This already works with an iterator, because array destructuring uses the > iterator protocol > > const [a, b] = { > 0: "ayy", > 1: "bee", > length: 2, > *[Symbol.iterator]() { >

Re: Proposal For A New Alternative Keyword To “this” For Classes

2019-03-09 Thread Jordan Harband
s extension of class fields > proposal) seems like it has potential to me, so it seems like an excellent > time for everyone here to tell me why it's awful and stupid. > > On Sun, 10 Mar 2019 at 06:59 Jordan Harband wrote: > >> The engine only has that knowledge when you

Re: Proposal For A New Alternative Keyword To “this” For Classes

2019-03-09 Thread Jordan Harband
free. > www.avast.com > <https://www.avast.com/sig-email?utm_medium=email_source=link_campaign=sig-email_content=webmail_term=link> > <#m_-8660865756228832385_DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2> > > On Sun, Mar 10, 2019 at 12:27 AM Jordan Harband wrote: > >> An addi

Re: Proposal For A New Alternative Keyword To “this” For Classes

2019-03-09 Thread Jordan Harband
An additional keyword like this would require a function to have a hidden reference back to the instance. However, especially for `class` methods, but also for ES5-style inheritance, or even for `class Foo {} Foo.prototype.bar = function () {}`, methods are *shared*. You might have a billion

Re: Proposal: export ** from './FooBar'

2019-03-02 Thread Jordan Harband
https://github.com/tc39/ecma262/pull/1174 adds `export * as someName from 'path'`; https://github.com/tc39/proposal-export-default-from is the proposal that you're looking for. On Fri, Mar 1, 2019 at 6:48 AM Mike Samuel wrote: > > > On Fri, Mar 1, 2019 at 1:35 AM Cyril Auburtin > wrote: > >>

Re: Proposal: switch expressions

2019-02-25 Thread Jordan Harband
story of the > syntax decisions? > > --David > > > On Feb 25, 2019, at 12:33 PM, Jordan Harband wrote: > > Additionally, https://github.com/tc39/proposal-pattern-matching - switch > statements are something I hope we'll soon be able to relegate to the > dustbin of history. &g

Re: Function Overloading or Pattern Matching of functions in Ecma

2019-02-25 Thread Jordan Harband
That only allows you to switch on things that have a string representation; object identity (more complex than the basic form that switch currently allows) is a particularly common use case that the pattern matching proposal addresses. On Sun, Feb 24, 2019 at 2:36 PM kai zhu wrote: > if it

Re: Proposal: switch expressions

2019-02-25 Thread Jordan Harband
Additionally, https://github.com/tc39/proposal-pattern-matching - switch statements are something I hope we'll soon be able to relegate to the dustbin of history. On Mon, Feb 25, 2019 at 6:01 AM David Koblas wrote: > I quite aware that it’s covered in do expressions. Personally I find do >

Re: Proposal: `Object.isEmpty(value)`

2019-02-13 Thread Jordan Harband
`Reflect.ownKeys(x || {}).length === 0`? On Wed, Feb 13, 2019 at 10:31 PM Isiah Meadows wrote: > This would be roughly equivalent to `Object.keys(value).length === 0`, > but with a few exceptions: > > 1. If `value` is either `null` or `undefined`, it gracefully falls > back to `false` instead

Re: add stage4 constraint - ease-of-minification

2019-02-12 Thread Jordan Harband
So effectively, you're arguing that stagnant tools should hold back evolution of the language, even when non-stagnant alternatives exist? On Tue, Feb 12, 2019 at 3:26 PM kai zhu wrote: > > Can you expand on what you mean by this, or provide an example of a > > feature that can't be "easily

Re: A way to fire logic at the end of completion of the current class method (regardless of super call order).

2019-02-09 Thread Jordan Harband
If the superclass constructor has a way to run any code after subclass constructors, then implementation details of the *subclasses* are then leaked. On Sat, Feb 9, 2019 at 2:15 AM Isiah Meadows wrote: > I've also had *several* scenarios where I could've used this > personally. I feel ES

Re: Introspect bind function targets

2019-02-04 Thread Jordan Harband
Given that you can also do `const c = (...args) => proto.call(null, ...args);`, and `Function.isSameTarget(a, c)` would presumably be `false`, can you elaborate more on the use case for this? On Mon, Feb 4, 2019 at 9:38 AM Sultan wrote: > A way to determine if two bound functions reference the

Re: returning non-Promise values from async functions and running them synchronously (or Promise.sync() idea)

2019-02-03 Thread Jordan Harband
Typically, APIs that are sometimes sync and sometimes async are called "z̲̗̼͙̥͚͛͑̏a̦̟̳͋̄̅ͬ̌͒͟ļ̟̉͌ͪ͌̃̚g͔͇̯̜ͬ̒́o̢̹ͧͥͪͬ" - unpredictable, hard to maintain, hard to understand. The general best practice is that a function should always be async, or always sync, but never the twain shall meet.

Re: idea: Array.prototype.remove

2019-02-03 Thread Jordan Harband
Why "remove" and not `.filter`, to produce a new array? On Sun, Feb 3, 2019 at 9:56 PM #!/JoePea wrote: > I sometimes find myself doing things like > > ```js > this.children.splice(this.children.indexOf(child), 1) > ``` > > but it seems that it will iterate the array twice. Maybe a new method

Re: Named factory functions

2019-02-03 Thread Jordan Harband
I suspect that would break a ton of code - ES6 name inference already broke some of mine, but I was able to work around it by using this kind of indirection. On Sun, Feb 3, 2019 at 11:02 AM Sultan wrote: > Where there any attempts to allow factory functions the ability to assume > the name of

Re: Dash-case keys

2019-01-29 Thread Jordan Harband
There's a difference, though, between private field access - an entirely distinct and new kind of thing - and normal property access, a well-established and understood thing. On Mon, Jan 28, 2019 at 11:53 PM Sultan Tarimo wrote: > This is expected and by design. For example

Re: Dash-case keys

2019-01-28 Thread Jordan Harband
i think if i can use something unquoted in an object literal, i'd expect to be able to use it in dot access - ie, `obj.font-size` - and then that problem arises. On Mon, Jan 28, 2019 at 3:43 PM Sultan Tarimo wrote: > The former as the following is equally invalid syntax errors: > > const font =

Re: Dash-case keys

2019-01-28 Thread Jordan Harband
is that a key called "font-size" or the subtraction of `size` from `font`? On Mon, Jan 28, 2019 at 1:48 PM Sultan wrote: > Is there any reason that dash-case keys are not supported in the object > literal syntax. > > For example: > > const style = { > font-size: 10 > } > > Compared to what

Re: Proposal: Default object method

2019-01-27 Thread Jordan Harband
Something that can be invoked has a `[[Call]]` slot, and is `typeof` "function". Adding a Symbol that makes something callable would have a number of effects - it would make `typeof` (one of the most robust operations in the language) unsafe, because it would have to access the Symbol method,

Re: Discussion: Module Reflection - import.reflect

2019-01-25 Thread Jordan Harband
In `import * as m from myModule`, `m.default` is already the default export; `Object.keys(m)` is already the list of export names, and `Object.entries(m).filter(([k, v]) => typeof v === 'function'))` is the list of functions. On Fri, Jan 25, 2019 at 5:27 AM Randy Buchholz wrote: > Would it be

Re: Proposal: enhanced case clause

2019-01-19 Thread Jordan Harband
Rather than investing more in switch statements, https://github.com/tc39/proposal-pattern-matching may be more compelling :-) On Sat, Jan 19, 2019 at 11:23 AM Sm In wrote: > *Before read: I'm not a native. so I may used some unnatural expression, > or non-sense sentence. I feel so sorry for

Re: Proposal: [Symbol.equals]

2019-01-19 Thread Jordan Harband
orkflow problems > most of us js-devs were originally hired to solve. > > On 18 Jan 2019, at 11:32 PM, Jordan Harband wrote: > > This thread would apply equally well to objects (there's no such thing as > a "json object" - json is a string, and once it's parsed into

Re: Proposal: [Symbol.equals]

2019-01-18 Thread Jordan Harband
=== jsonStringifyCanonical({ > meta: {label: "point #32"}, > data: {z: 3, y: 2, x: 1} > }) > ); > }()); > ``` > > > [1] testing aa “==“ b by comparing their canonical json-representation > https://github.com/kaizhu25

Re: Proposal: [Symbol.equals]

2019-01-18 Thread Jordan Harband
It's pretty important that the meaning `===` not be able to change. On Fri, Jan 18, 2019 at 10:33 AM ViliusCreator wrote: > What about having Symbol.equals? > > For example, for now this is what it does: > > ```js > > class Position { > constructor(o) { > this.x = o.x instanceof

Re: De-structuring array arguments

2019-01-17 Thread Jordan Harband
I'm not sure what you mean, that should certainly be possible today. In node, I get this: ``` function foo ([a, b] = [1, 2]) { return [a, b]; } foo([2, 3]) // [2, 3] foo() // [1, 2] ``` On Thu, Jan 17, 2019 at 9:50 AM Sultan wrote: > Consider the following is not possible today: > >

Re: Re: Proposal: Symbol Linked to `typeof`

2019-01-16 Thread Jordan Harband
https://github.com/michaelficarra/proposal-first-class-protocols may be relevant. On Wed, Jan 16, 2019 at 9:06 AM Augusto Moura wrote: > I don't think string namespaced names are the right feature here > > Namespaces are intended mainly to avoid conflicts with names when > sharing a global

Re: Re: Proposal: Class Templates

2019-01-16 Thread Jordan Harband
https://github.com/michaelficarra/proposal-first-class-protocols may be a more palatable approach here. On Wed, Jan 16, 2019 at 9:41 AM ViliusCreator wrote: > Also, using `new (Abc(4, 5, 6))(1, 2, 3)` causes error ` Uncaught > TypeError: Abc(...) is not a constructor`. > > > > >

Re: Proposal: Named de-structuring arguments.

2019-01-16 Thread Jordan Harband
See https://github.com/zkat/proposal-as-patterns On Wed, Jan 16, 2019 at 12:24 AM Sultan wrote: > The ability to both name and de-structure an argument. > > Relying on the spread operator does not archive the same effect > considering that the spread operator "by design" has some short-comings

Re: Proposal: Symbol Linked to `typeof`

2019-01-15 Thread Jordan Harband
to help me. Since imports use paths, if I move a file refactoring can be > painful. With an IDE extension, I can trigger an event when I move a file > to prompt “Update all imports?”. It can parse my project and update all > imports to point to the right place. > > > > *From:* es-di

Re: Proposal: Symbol Linked to `typeof`

2019-01-15 Thread Jordan Harband
`.constructor` is unreliable, and can be easily forged - of course, `Symbol.typeof` would create the same unreliability with one of the few truly reliable operators in the language. On Tue, Jan 15, 2019 at 12:38 PM J Decker wrote: > > > On Sat, Jan 12, 2019 at 8:19 AM Randy Buchholz > wrote: >

Re: Bind function without thisArg

2019-01-13 Thread Jordan Harband
``` var foo = function(a) { console.assert(this === obj) }; var obj = { foo() { return foo.apply(this, arguments); } }; ``` ? On Sun, Jan 13, 2019 at 10:01 PM Ranando King wrote: > Bind is just a wrapper function provided by the engine. You can always > create your own: > > ```js > function

Re: New Proposal: ES Call Stack

2019-01-13 Thread Jordan Harband
"who calls function B" has, and must have, no bearing on how function B behaves. Every single call site that passes identical (`Object.is`) arguments must behave the same. Am I misunderstanding what you mean? On Sun, Jan 13, 2019 at 9:50 PM Ranando King wrote: > That's all fine and dandy until

Re: Array.create and Function.create

2019-01-11 Thread Jordan Harband
: >> >> 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 >>

Re: Array.create and Function.create

2019-01-10 Thread Jordan Harband
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

Re: Array.create and Function.create

2019-01-10 Thread Jordan Harband
econdary consequence allow engines to make stronger assumptions with > regards to operations on these structs. > > On Thu, Jan 10, 2019 at 9:48 AM Jordan Harband wrote: > >> An array with no prototype wouldn't have any of the iteration methods on >> it; a function with no prototype wo

Re: Array.create and Function.create

2019-01-09 Thread Jordan Harband
An array with no prototype wouldn't have any of the iteration methods on it; a function with no prototype wouldn't have .call/.bind/.apply - length and name are own properties of functions, and length is an own property of an array, so you'd get those regardless. (`Array.from({ length: 1000 })`

Re: How to prettify output of objects in the console, when using get/set, like browsers do?

2019-01-09 Thread Jordan Harband
`console` isn't part of the language; node and browsers have their own implementations (which is likely covered by an HTML spec), so you'd want to look into it there. node's `util.inspect`, for example, provides a `util.inspect.custom` symbol that's invoked to get a custom string version of the

Re: Proposal: Add `NoSubstitutionTemplate` to `StringLiteral` Definition

2019-01-09 Thread Jordan Harband
import path specifiers are another. On Wed, Jan 9, 2019 at 10:16 AM T.J. Crowder < tj.crow...@farsightsoftware.com> wrote: > On Wed, Jan 9, 2019 at 5:36 PM FERREIRA, ERIC B > wrote: > > I contend that adding `NoSubstitutionTemplate`s to the definition of > > `StringLiteral` will bring the

Re: Proposal: Array.prototype.count

2019-01-07 Thread Jordan Harband
All the iteration methods are a specific case of reduce, in that you can implement them all with reduce. On Mon, Jan 7, 2019 at 11:27 AM Ranando King wrote: > Isn't that just a specific case of Array.prototype.reduce? > > ```js > const evenNumberCount = [1,2,3,4,5].reduce((acc, val) => { !(val

Re: Fixed-length untyped arrays

2018-12-21 Thread Jordan Harband
Is there any evidence that existing arrays *prevent* engines from making optimizations? I believe (and any implementors, please correct me if I'm wrong) that the most common approach is to guess the likely maximum size for the array, double it, and then allocate that much memory - and thus all the

  1   2   3   4   5   >