Barth Zalewski - 1 year ago 100

Javascript Question

In Javascript Harmony, we can for example do the following:

`var maths = {`

sum (...args) {

let r = 0;

for (let num of args) {

r += num;

}

return r;

}

};

maths.sqr = n => n * n;

I just wondered if there is any way to use an arrow function, like

`sqr`

`sum`

Recommended for you: Get network issues from **WhatsUp Gold**. **Not end users.**

Answer Source

You could just write it as literal.

```
var maths = {
sqr: n => n * n,
sum (...args) {
let r = 0;
for (let num of args) {
r += num;
}
return r;
}
};
console.log(maths.sqr(5));
console.log(maths.sum(2, 4, 5));
```

Recommended from our users: **Dynamic Network Monitoring from WhatsUp Gold from IPSwitch**. ** Free Download**