andrysimo1997 at gmail.com (2018-11-28T22:05:09.326Z)
I assumed that `F` was called with `new`, providing a valid `this` object
too and I've used the object spread syntax to avoid a function call.
Anyway I prefer
```js
F(par1, par2, ..., parN) {
this.par1 = par1;
this.par2 = par2;
...
this.par3 = par3;
}
```
to this:
```js
F(arg) {
let {par1, par2, ..., parN} = arg;
Object.assign(this, arg);
}
```
Because there is no function call (` Object.assign `), no useless object
creation (when you pass arguments) nor duplication. The first should be
faster. And it is obviously clearer.
So:
```js
F(.par1, .par2, ..., .parN) {}
```
Could be fast too. Maybe also clear, because when you learn what it
does...you cannot misundertood it later.
I assumed that `F` was called with `new`, providing a valid `this` object too and I've used the object spread syntax to avoid a function call. Anyway I prefer ```js F(par1, par2, ..., parN) { this.par1 = par1; this.par2 = par2; ... this.par3 = par3; } ``` to this: ```js F(arg) { let {par1, par2, ..., parN} = arg; Object.assign(this, arg); } ``` Because there is no function call (` Object.assign `), no useless object creation (when you pass arguments) nor duplication. The first should be faster. And it is obviously clearer. So: ```js F(.par1, .par2, ..., .parN) {} ``` Could be fast too. Maybe also clear, because when you learn what it does...you cannot misundertood it later. Il giorno mer 28 nov 2018 alle ore 22:51 Ranando King <kingmph at gmail.com> ha scritto: > Arguments is only deprecated in strict mode. > > ```js > F(arg) { > let {par1, par2, ..., parN} = arg; > Object.assign(this, arg); > } > ``` > > This version works in strict mode, but it's less clear what parameters > should be passed. I used `Object.assign` because I assumed that `F` was > called with `new`, providing a valid `this` object. Otherwise, your > original example would either throw in strict mode, or add your parameters > to "global", unless it was called with `Function.prototype.call`. > > On Wed, Nov 28, 2018 at 3:36 PM Simo Costa <andrysimo1997 at gmail.com> > wrote: > >> Ops I saw the now ahahah sorry. But anyway there is a function call and >> an object creation and you are forced to pass arguments using an object >> (not so bad but...another object creation). >> To avoid the function call I would do: >> ```js >> F({par1, par2, ..., parN}) { >> this = {...arguments[0]}; >> } >> ``` >> Another thing...`arguments` is deprecated, right? >> > -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20181128/75c9758f/attachment.html>