I'm learning ES6 fat arrow functions. What is the correct way to change this code, so as to be able to put another line, even const a = 100;
in the place indicated so that I can add some more lines to this function?
IMAdded: (options, args) => ({ IMAdded: { filter: newIM => true, *need to add another line here* }, }),
Update:
Here's ES6 code that runs:
const subscriptionManager = new SubscriptionManager({ schema, pubsub, setupFunctions: { APPTAdded: (options, args) => ({ APPTAdded: { filter: appointment => (true), }, }), });
I'd like to add some more lines into the code that returns true
.
It's a new feature that introduced in ES6 and is called arrow function. The left part denotes the input of a function and the right part the output of that function.
An arrow function doesn't have its own this value and the arguments object. Therefore, you should not use it as an event handler, a method of an object literal, a prototype method, or when you have a function that uses the arguments object.
Introduction. The 2015 edition of the ECMAScript specification (ES6) added arrow function expressions to the JavaScript language. Arrow functions are a new way to write anonymous function expressions, and are similar to lambda functions in some other programming languages, such as Python.
Since regular functions are constructible, they can be called using the new keyword. However, the arrow functions are only callable and not constructible, i.e arrow functions can never be used as constructor functions. Hence, they can never be invoked with the new keyword.
If you want to convert the following method into having more lines:
{ filter: appointment => true }
You have to add curly braces and a return
statement:
{ filter: appointment => { // ... add your other lines here return true; } }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With