Conditional assign operator

2020-04-13 Thread Sultan
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 same can be said for: var undef undef ?= 1 Which could both be transpired to type obj[foo] === 'undefined' && obj[foo] = 1 or type a

Re: syntax for case ranges

2020-01-31 Thread Sultan
wrote: > >> This sounds like https://github.com/tc39/proposal-pattern-matching >> >> El 31/1/20 a les 10:57, Sultan ha escrit: >> >> For example, the following: >> >> switch (value) { >> case 0...9: break >> case 'a'...'z': break &g

syntax for case ranges

2020-01-31 Thread Sultan
For example, the following: switch (value) { case 0...9: break case 'a'...'z': break } ___ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss

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

2019-09-07 Thread Sultan
Can you currently do this with the "super" keyword outside of classes? On Fri, Sep 6, 2019 at 9:16 PM Jordan Harband wrote: > `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

Symbol.inspect

2019-04-04 Thread Sultan
Like Symbol.iterator, a Symbol.inspect symbol for use in implementing cross-platform console display introspection. Currently node has something akin to this with a magic inspect method on objects. This would pave a cow path for how different platforms can afford this ability to consumers

Re: Proposal: Static Typing

2019-03-24 Thread Sultan
Counter proposal: A uniform signature for types, denoted by: const name: primitive-type?; Where primitive types are denoted as: const name: symbol; const name: string; const name: number; const name: object; const name: boolean; const name: function; And types can later be extended to afford

Destructuring for Array-like objects

2019-03-19 Thread Sultan
Afford array destructuring to Array-like objects. const [a, b] = {0: a, 1: b, length: 2} ___ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss

Name-spaced cross-realm objects

2019-03-11 Thread Sultan
The following is currently possible with setTimeout from the browser const i = setTimeout(() => {}) Where "i" is a number from 0 incrementing towards infinity. This however has the issue that it is entirely global, and as the title of the post suggests the idea is to strike a middle ground

Re: Introspect bind function targets

2019-02-05 Thread Sultan Tarimo
For example given a set of values. A function that checks whether the values of the object are equal could shallow compare the values of each property in the object. However this heuristics falls short for inline/bound functions that share the same target/backing but are only different with

Introspect bind function targets

2019-02-04 Thread Sultan
A way to determine if two bound functions reference the same target function. For example: function proto () {} const a = proto.bind(null, 1) const b = proto.bind(null, 2) console.assert(Function.isSameTarget(a, b)) ___ es-discuss mailing list

Named factory functions

2019-02-03 Thread Sultan
Where there any attempts to allow factory functions the ability to assume the name of the binding they are assigned to? Consider the following: function factory () { return function () {} } var foo = factory() console.assert(foo.name === 'foo') ___

Promise.resolve

2019-02-02 Thread Sultan
Was there any reason Promise.resolve was not afforded the ability to dispatch outside of `this` pointing to the `Promise` constructor? For example: const {resolve} = Promise resolve(1234) This currently throws. ___ es-discuss mailing list

Re: Dash-case keys

2019-01-28 Thread Sultan Tarimo
This is expected and by design. For example obj[‘#invalidPrivateSigil’] is also not invalid. The affordances would be the same. ___ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss

Re: Dash-case keys

2019-01-28 Thread Sultan Tarimo
That might have been the case, but the expectation that an unquoted form should equally have a quoted form or vice-versa is not an issue in practice given the presence of a similar but opposite semantic in the private sigil access notation proposal: object.#validPrivateSigil ->

Re: Dash-case keys

2019-01-28 Thread Sultan Tarimo
The former as the following is equally invalid syntax errors: const font = 1 const size = 1 const a = { font-size: 10 } const b = { font+size: 10 } ___ es-discuss mailing list es-discuss@mozilla.org

Dash-case keys

2019-01-28 Thread Sultan
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 one needs to do today: const style = { 'font-size': 10 } ___ es-discuss mailing list

De-structuring array arguments

2019-01-17 Thread Sultan
Consider the following is not possible today: function foo ([a, b] = [1, 2]) {} foo([2, 3]) While the the following is outside of function arguments: const arr = [1, 2] const [a, b] = arr Is there any reason for the current status quo? ___

Proposal: Named de-structuring arguments.

2019-01-16 Thread Sultan
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 related to exotic objects when the objects in question have a rich prototype you want to preserve.

Re: Bind function without thisArg

2019-01-14 Thread Sultan
t; }, >> prototype: { >> configurable: true, >> writable: true, >> value: fn.prototype >> } >> }); >> } >> ``` >> >> This should apply your bound arguments before any arguments supplied by >> the calle

Bind function without thisArg

2019-01-13 Thread Sultan
Consider the following example: var foo = (function(a) { console.assert(this === obj) }).bind(undefined, 1) var obj = {foo: foo} Calling foo from obj: obj.foo(1) Would result in an assertion. How does one go about preserving the this reference of the caller. That is i want to use .bind to only

Re: Proposal: Placeholder operator

2019-01-11 Thread Sultan
const [ , setState] = useState(0) Thanks i forgot about that. On Fri, Jan 11, 2019 at 5:31 PM Claude Pache wrote: > > > > Le 11 janv. 2019 à 14:02, Sultan a écrit : > > > > Placeholder operator: ! > > > > Use in function parameters(maintains arity without

Proposal: Placeholder operator

2019-01-11 Thread Sultan
Placeholder operator: ! Use in function parameters(maintains arity without creating a named binding): const foo = (a, b, !) => {} Use in de-structuring(allows you to capture further along a tuple without creating a named binding): const [!, setState] = useState(0)

Syntax operator for "default assignment if value doesn't exits"

2019-01-11 Thread Sultan
An operator syntax for the the "typeof" pattern used to detect if a environment/object has a value: if (typeof variable === 'undefined') {...} if (typeof object.key === 'undefined') {...} This could manifest in destructuring as the following var fn = ({ key ||= 1 }) => { } And with variables

Re: Array.create and Function.create

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

Re: Array.create and Function.create

2019-01-10 Thread Sultan
nes" or as close to a C-like: a = malloc(sizeof(void*)*10) as JavaScript could potentially get. On Thu, Jan 10, 2019 at 11:54 AM Jordan Harband wrote: > Why would this be better than `const a = []; Object.setPrototypeOf(a, > null)`? > > On Thu, Jan 10, 2019 at 12:09 AM Sultan wro

Re: Array.create and Function.create

2019-01-10 Thread Sultan
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 })` already creates an array of length 1000 > withou

Array.create and Function.create

2019-01-09 Thread Sultan
Identical to Object.create but for Arrays and Functions. This method will allow you to create arrays with no prototype. This would allow authors the ability to use array objects as state containers without the need to resort to index-based objects with Object.create(null, length) When you want

Re: Callable objects protocol

2018-12-04 Thread Sultan
>>> > }, >>> > } >>> > function makeCallable(obj) { return new Proxy(obj, handler) } >>> > >>> > // Your example, ported >>> > const obj = makeCallable({ >>> > [callable]: function (...args) { return th

Callable objects protocol

2018-12-04 Thread Sultan
Something along the lines of Symbol.iterator protocol for defining callback objects i.e: Symbol.callable: const obj = { [Symbol.callable]: function (...args) { return this[Symbol.for('value')] }, [Symbol.for(''value')]: 'value', } assert(obj() === 'value')

Re: Arrow methods

2018-11-16 Thread Sultan
proposal. > > This leaves out self-binding, but you could always use a local variable if > necessary. (It's like one extra line, maybe 3, and it's not common at all.) > On Fri, Nov 16, 2018 at 15:09 Sultan wrote: > >> The missing colon ":" is intentional. >> >>

Re: Arrow methods

2018-11-16 Thread Sultan
The missing colon ":" is intentional. On Fri, Nov 16, 2018 at 10:57 PM J Decker wrote: > > > On Fri, Nov 16, 2018 at 11:23 AM Sultan wrote: > >> As the name suggests; An update to the grammar related to methods on >> objects/classes to support arrow method

Arrow methods

2018-11-16 Thread Sultan
As the name suggests; An update to the grammar related to methods on objects/classes to support arrow methods: today: {render() { return 'Hello' }} proposed addition: {render() => 'Hello'} This could be some-what linked to class fields in the class variant; That is what does "this" refer to when

Re: Proposal: defer keyword

2018-09-20 Thread Sultan
What stops you from doing this with try...finally? function doSomeDbWork() { try { return databasepool.getConnection(); } finally { connection.release(); } } On Thu, Sep 20, 2018 at 1:01 PM, Ayush Gupta wrote: > Apologies, I meant to use `async-await` in the example but I missed it. > >

Re: Inline ES Modules

2018-06-20 Thread Sultan
is solved, does the below mean anything > if (Math.random() < 0.5) { > module School { > export function getPersonType() {} > } > } > > If not, if inline modules are defined eagerly, what advantages, besides > making life easier for transpiler writers, would inline mod

Inline ES Modules

2018-06-17 Thread Sultan
Are there any open proposals/discussions related to creating ES modules inline? For example: ``` import getPersonType from School module School { export function getPersonType (person) { switch (person) { case 'Teacher': return 'A teacher' case 'Director': return 'A director' } } }

Re: Proposal: allow primitives to be explicitly returned from constructors

2018-04-20 Thread Sultan
One of the use case for this is – given a function that is either one that returns an instance or one that returns an explicit return value, but would otherwise throw if invoked without the "new" keyword. Always being able to safely invoke it with "new" is a nice guarantee to have that wouldn't

Re: EcmaScript Proposal – Private methods and fields proposals.

2018-04-17 Thread Sultan
om> wrote: > On 04/17/2018 02:26 PM, Sultan wrote: > >> In the transpilation you created the field using "registry.set(this, {id: >>> 0})" >>> in the constructor. If you then claim that any write to the field can >>> also create it,

Re: EcmaScript Proposal – Private methods and fields proposals.

2018-04-17 Thread Sultan
gle.com> wrote: > On 04/17/2018 01:50 PM, Sultan wrote: > >> >That would contradict your previous answer to the hijacking question. >> >> Can you point out the contradiction? The private field is still being >> written to by the providing class. >> > &g

Re: EcmaScript Proposal – Private methods and fields proposals.

2018-04-17 Thread Sultan
an you provide an example of what this looks like with the current public/private fields proposals? On Tue, Apr 17, 2018 at 11:20 PM, Waldemar Horwat <walde...@google.com> wrote: > On 04/16/2018 05:47 PM, Sultan wrote: > >> >An instance has a fixed set of private fields whi

Re: EcmaScript Proposal – Private methods and fields proposals.

2018-04-16 Thread Sultan
fields? Not sure i understood what you mean by this? On Tue, Apr 17, 2018 at 1:43 AM, Waldemar Horwat <walde...@google.com> wrote: > On 04/13/2018 09:41 PM, Sultan wrote: > >> >Writing your private field to an object that's not an instance of your >> class. >> &g

Re: EcmaScript Proposal – Private methods and fields proposals.

2018-04-13 Thread Sultan
AM, Michael Theriot < michael.lee.ther...@gmail.com> wrote: > I'd imagine that would fail the same way proxies fail on typed arrays. > > > On Apr 13, 2018, at 6:26 PM, Waldemar Horwat <walde...@google.com> > wrote: > > > >> On 04/13/2018 01:38 AM, Sultan wrote:

Re: EcmaScript Proposal – Private methods and fields proposals.

2018-04-13 Thread Sultan
The proposal is an explainer with regards to an alternative sigil-less syntax to back private fields/methods. >What does private(this)[property] do? "private(this)[property]" and alternatively "private[property]" or "private.property" all invoke access of a private "property" on the "this"

Re: EcmaScript Proposal – Private methods and fields proposals.

2018-04-12 Thread Sultan
03-21#10ivb-javascript-classes-11 > > - > > Isiah Meadows > m...@isiahmeadows.com > > Looking for web consulting? Or a new website? > Send me an email and we can get started. > www.isiahmeadows.com > > > On Thu, Apr 12, 2018 at 2:11 PM, Sultan <

EcmaScript Proposal – Private methods and fields proposals.

2018-04-12 Thread Sultan
[Strawman] Private methods and fields for JavaScript: https://github. com/thysultan/proposal-private-methods-and-fields ```js class A { private id = Symbol('unique') equal(instance, property) { return private(this)[property] == private(instance)[property] } } const x = new A()