Hand Helper with ES6

I want to write a helper block to check if a section should be displayed for a specific role:

{{#allowApprover "EMP"}} 
<!-- content -->
{{/allowApprover}}

And the assistant is defined as:

allowApprover: (currentRole, options) => {
     return permit(currentRole) ? options.fn(this) : options.inverse(this)
}

The code above does not work, I think, because it thisbehaves differently in arrows, but I don’t know how to do it, and another question: what does options.fnit exactly?

+4
source share
1 answer

I had the same problem with this error message:

Cannot read property '_sections' of null 

As @torazaburo commented, in this case you should write a regular function instead of an arrow function.

That's why, according to a wonderful article from Mozilla.

ES6 in Depth Arrow Functions

What is it?

. . .

, :

- , object.method(). , .

+1

All Articles