Answer the question
In order to leave comments, you need to log in
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)
Answer the question
In order to leave comments, you need to log in
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)
- 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 questionAsk a Question
731 491 924 answers to any question