L
L
lorentso2021-08-04 18:38:34
Pug
lorentso, 2021-08-04 18:38:34

How to pass JS methods as mixin parameters?

I have a question. Is it possible to pass some method to the mixin and, accordingly, change it to any other.
Example.

- arr = [1,2,3,4,5,6,7,8]

mixin paramForMethod(a)
   - newArr = a.slice(0,1)
        p= newArr

+paramForMethod(arr)


Can I use some syntax to change slice to, for example, splice, or filter? As I understand it, the problem is at the point before the method call. It cannot be passed through a parameter.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
0
0xD34F, 2021-08-04
@lorentso

JS is JS, as usual:

- arr = [ 1, 2, 3, 4, 5, 6, 7, 8 ]

mixin xxx(arr, method, ...args)
   - newArr = arr[method](...args)
   p= newArr

+xxx(arr, 'slice', 2, 5)
+xxx(arr, 'filter', n => n & 1)

True, it is not clear why pass the name of the method at all and perform some manipulations inside, if this can be done outside:
- arr = [ 1, 2, 3, 4, 5, 6, 7, 8 ]

mixin xxx(arr)
  ul
    each n in arr
      li= n

+xxx(arr.slice(-3))
+xxx(arr.filter(n => !(n % 3)))

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question