Security update to Drupal 8.4.6
[yaffs-website] / node_modules / generate-function / example.js
1 var genfun = require('./')
2
3 var multiply = function(a, b) {
4   return a * b
5 }
6
7 var addAndMultiplyNumber = function(val) {
8   var fn = genfun()
9     ('function(n) {')
10       ('if (typeof n !== "number") {') // ending a line with { will indent the source
11         ('throw new Error("argument should be a number")')
12       ('}')
13       ('var result = multiply(%d, n+%d)', val, val)
14       ('return result')
15     ('}')
16
17   // use fn.toString() if you want to see the generated source
18
19   return fn.toFunction({
20     multiply: multiply
21   })
22 }
23
24 var addAndMultiply2 = addAndMultiplyNumber(2)
25
26 console.log(addAndMultiply2.toString())
27 console.log('(3 + 2) * 2 =', addAndMultiply2(3))