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 <[email protected]>
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 <[email protected]>
> 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?
>>
>
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss