]> gerrit.simantics Code Review - simantics/district.git/blob - org.simantics.maps.server/node/node-v4.8.0-win-x64/node_modules/npm/node_modules/request/node_modules/har-validator/node_modules/is-my-json-valid/node_modules/generate-function/example.js
Adding integrated tile server
[simantics/district.git] / org.simantics.maps.server / node / node-v4.8.0-win-x64 / node_modules / npm / node_modules / request / node_modules / har-validator / node_modules / is-my-json-valid / 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))