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
}
___
es-discuss mailing list
If you want to add this you will need a champion, see
https://github.com/tc39/ecma262/blob/master/CONTRIBUTING.md#new-feature-proposals
-- Oriol
El 29/5/19 a les 21:15, Григорий Карелин ha escrit:
I agree.
So, what does community think? Do we want to have “destructuring picking” sugar
in JS
> About being unique, you can always
> `document.querySelector('[attribute="' + value +'"]')`
This code is vulnerable to CSS injection, input values shouldn't be
inserted raw into queries!
You can use `CSS.escape` to sanitize.
-- Oriol
__
roperties in property descriptors and read them later, ignoring the receiver
when calling getters and setters, assuming all objects are extensible and all
properties are configurable, etc.
--Oriol
pEpkey.asc
Description: pEpkey.asc
___
es-discuss mailin
;
const {compare} = new Intl.Collator(undefined, {sensitivity: "base"});
if (manyStrings.some(s => compare(s, stringOne) == 0)) {
// Yes, it was found
}
```
-- Oriol
pEpkey.asc
Description: pEpkey.asc
___
es-discuss maili
obscure indeed.
-- Oriol
___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss
Object(value) {
> return value != null && (
> typeof value === "object" ||
> typeof value === "function"
> )
> }
No, `typeof` is not reliable, because it's implementation-defined for
non-standard non-callable exotic objects.
For
.
And I don't really see the point, constructors are supposed to construct
objects. If you want primitives, you can always use function calls.
-- Oriol
___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss
t read the handler spec in advance?
Yes, the spec does not allow this. But there was a proposal about doing that in
some cases, in order to improve performance.
-- Oriol
___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss
Hi Joe, I used a 2nd proxy as the handler in order to only allow the desired
traps.
Sure, I could have defined all blacklisted traps in an ordinary object, and
make them throw an error.
But this wouldn't be future-proof in case new traps are eventually added.
Whitelisting is safer.
-- Oriol
Be aware your code breaks pair surrogates, which might be undesirable:
```js
var str = "a_\uD83D\uDE80_b";
str.split("").reverse().join(""); // "b_\uDE80\uD83D_a" :(
[...str].reverse().join(""); // "b_\uD83D\uDE80_a" :)
```
--Oriol
> the last point doesn't haven't the same usability as my proposal since with
> mine multiple different objects can be selected from at a time
I believe that you could use Bob's proposal like this:
```js
var obj = {...obj1.{prop1, prop2}, ...obj2.{prop3, prop4}};
```
--
"getOwnPropertyDescriptor"];
let handler = new Proxy(Object.create(null), {
get(_, trap, receiver) {
if (!allowed.includes(trap)) return error;
}
});
this.emit('some:event', new Proxy(obj, handler));
```
-- Oriol
___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss
block;
}
return action({ data: response.data });
}
```
- Oriol
___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss
t;console.log(1);";
document.documentElement.appendChild(s);
console.log(2);
```
The output will be `1`, `2`. The script runs immediately, it's not async.
- Oriol
___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss
> I believe there's a very simple way to do this today: new Map([...mapA,
> ...mapB, ...mapC]).
But this only works if you want to create a new map, of course. Can't be used
to assign to an existing map.
- Oriol
___
es-discuss mailing list
es-d
.
- Oriol
___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss
`addEventListener` in not part of ECMAScript. It's defined in the DOM spec. You
should send your proposal to the WHATWG.
--Oriol
___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss
something
more simple and reliable like
```js
function isObject(value) {
return Object(value) === value;
}
function isObject(value) {
return new function(){ return value } === value;
}
```
--Oriol
___
es-discuss mailing list
es-discuss@mozilla.org
Consider using an async function:
```js
async function promiseFunction() {
return someValue;
}
```
--Oriol
___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss
arg: 2 }
```
--Oriol
___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss
```js
class FooBar extends Element {
constructor() {
console.log("patched in Element");
let el = document.createElement('foo-bar');
return Object.setPrototypeOf(el, FooBar.prototype);
}
}
```
-Oriol
___
es-discuss mailing list
of the value they return, they can also have desirable side-effects.
--Oriol
___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss
See https://esdiscuss.org/topic/strict-relational-operators
--Oriol
___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss
Instead of `thrown: false` or `thrown: false`, why not `type: "normal"`, `type:
"return"` or `type: "throw"`? This is what completion records use.
-Oriol
___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss
would expect this:
```js
let locked = Object.lock({});
let inherits = Object.create(locked);
Reflect.get(locked, "foo"); // TypeError
Reflect.get(locked, "foo", {}); // TypeError
Reflect.get({}, "foo", locked); // undefined
Reflect.get(inheri
uldn't `!` also be excluded, then?
> Future: Extending of operators
I don't think this can work if you don't define a way to determine the operands.
--Oriol
___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss
the need to add new syntax for this.
--Oriol
___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss
There is a `String#matchAll` proposal in stage 1.
https://github.com/tc39/String.prototype.matchAll<http://%20https://github.com/tc39/String.prototype.matchAll>
Oriol
___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozil
.
And then there are proxies. Taking them into account, I don't think there is
any reasonable way to compare objects.
So I think it's better if each person writes the code that compares objects
according to their needs.
--Oriol
___
es-discuss mailing list
es-discuss
enough of a nightmare.
--Oriol
___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss
Not only `size`. All `get`, `set`, `has`, etc. algorithms in the spec are O(n).
But as explained in
http://www.ecma-international.org/ecma-262/7.0/index.html#sec-map-objects,
> Map object must be implemented using either hash tables or other mechanisms
> that, on average,
> provide access
own property
!!Object.getOwnPropertyDescriptor(p, "foo"); // true
// [[HasProperty]] returns false
"foo" in p; // false
```
-Oriol
___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss
;foo"); // true
delete obj.foo;
// [[HasProperty]] returns false
"foo" in obj; // false
```
-Oriol
___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss
);
q.pop(); // 2
q.pop(); // 3
q.pop(); // undefined
```
-- Oriol
___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss
> I fixed it by putting the function inside `Object()`
You can also use the comma operator:
```js
var anon = (0, function () {});
anon.name; // ""
```
;Oriol
___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.or
to change that. Maybe some day we will have
`Object.isConstructor`.
;Oriol
___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss
ou can usually translate one syntax to the other, but you
may need ES6 features like `new.target`, `super` or `setPrototypeOf`.
-- Oriol
___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss
Not sure if I'm missing something, but wouldn't it be trivial to code that
constructor in JS?
```js
class Result {
constructor (type, value=true) {
this[type] = value;
}
}
function add(data) {
if (data !== Object(data)) {
return new Result('error', new Error('The data is not an
Object literals (object initializers) are just a convenient way to create a new
ordinary object which (initially) inherits from `Object.prototype`, and
populate it with some properties.
I don't think you should be able to distinguish them from similar objects not
created using object
In my opinion it's a bit incoherent that each object-coercible type behaves
differently when coercing symbols to it.
Symbols can be explicitly coerced to strings, but not implicitly:
```js
String(Symbol("abc")); // "Symbol(abc)"
Symbol("abc") + ""; // TypeError
```
Symbols can't be coerced to
But as
Mike Samuel mentioned, JSON strings containing U+2028 or U+2029 are not valid
JS expressions. I think it would make sense for `JSON.stringify` to escape
these.
-Oriol
___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org
I disagree with silently ignoring property access on null/undefined.
> Early errors are nice
Yes, exactly. Errors should fail early and loudly. That's why the strictness of
strict mode is useful.
> It's no weirder that `123.foo` not throwing.
No, it's entirely different, because numbers
orks like this:
```
(f ? g)(x) = f(g(x))
```
So I think it would be more intuitive to use `<=<`, which would call the right
operand first, and then call the left operand with the result of the right one.
,Oriol
___
es-discuss mailing list
es-disc
can be sure it will be a strict mode
function, it will be extensible, and won't have any additional non-configurable
own property. Then you will have less problems with proxy invariants.
-Oriol
___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.
in sloppy mode, and Firefox to never add them. So
I think both follow the spec.
- Oriol
___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss
> Could there be a Proxy.hasBeenRevoked(proxy) method?
The Proxy constructor only accepts targets and handlers when they are objects
and are not revoked proxies.
I wonder what's the point of not allowing revoked proxies but allow revocable
proxies which may be revoked later.
Anyways, this
Probably, because symbols are primitive values, and constructors only create
and initialize objects.
So you are supposed to call it as a function instead of as a a constructor.
That said, it might make sense for `new Symbol()` to return a symbol object.
But instead, you can use
> There are no items in `[]` so that doesn't seem like a true statement to me.
It's true by [Vacuous_truth](https://en.wikipedia.org/wiki/Vacuous_truth).
> So, at least consistency pulls towards `false`.
You are misunderstanding what `includes` does when there is no argument.
```js
What's the point of using `reduce` instead of `every`?
```js
Array.prototype.includesAll = function (...args) {
return args.every(item => this.includes(item));
}
```
I disagree with this test
```js
expect([2, 3].includesAll()).toBe(false)
```
The array `[2,3]` includes all items in `[]`. So
Array.prototype.includes uses the second argument as the starting index.
Therefore, these calls would be identical, but you want them to behave
differently:
```
["a"].includes("a", 0); // true -- "a" can be found at position 0
["a"].includes(...["a", 0]); // false -- 0 can't be found in the
I agree with Bergi.
> Brendan Eich and think he understood that fairly
I can't see that. He says things like "what's to propose?", "what is declare? I
don't think core language needs to grow", "What does this have to do with
promises?", "I don't see the point" and "It's not making sense,
As Isiah Meadows said, you can just use variables.
```
var removeNode = true;
control.dispose(removeNode);
```
```
var silent = true,
disableValidation = true,
destroyOldValue = false;
model.set('foo', newValue, {silent, disableValidation, destroyOldValue});```
From:
`setTimeout` is not part of ECMAScript. You should suggest this to WHATWG
instead.
- Oriol
From: m...@adriansieber.com
Date: Mon, 25 Apr 2016 17:35:50 +
Subject: Proposal: Switch position of delay and callback in signature of
`setTimeout()`
To: es-discuss@mozilla.org
Everytime I
They are no necessary the same:
```js
var _Object = window.Object,
Object = function() {};
class Foo1 {
constructor() {}
}
class Foo2 extends Object {
constructor() { super(); }
}
_Object.getPrototypeOf(Foo1.prototype); // _Object.prototype
_Object.getPrototypeOf(Foo2.prototype); //
ore
initialization
```
And `let` variables can't be redeclared:
```js
let foo = 123; // SyntaxError: redeclaration of let foo
```
Is this behaviour intended? Is there any way to take `foo` out of the TDZ, so
that I can assign values and read them?
- Or
56 matches
Mail list logo