javascript - Arrow function in object definition -


in javascript harmony, can example following:

var maths = {    sum (...args) {       let r = 0;       (let num of args) {          r += num;       }       return r;    } }; maths.sqr = n => n * n; 

i wondered if there way use arrow function, sqr within object definition, sum.

you write literal.

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


Comments

Popular posts from this blog

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -