I'm working with this print library. What I'm trying to do now is build up my print payload. Right now when it's no dynamic it looks like this:
serialPort.on('open',function() {
var printer = new Printer(serialPort);
printer.on('ready', function() {
printer
.printLine('text line 1')
.printLine('text line 2')
.printLine('text line 3')
.print(function() {
console.log('done');
//do other stuff
});
});
});
The issue I'm having is figuring out how to build up my print payload so that I can dynamcially create my string of .whatever().whatever().print()
to actually do the printing.
I ran across this post and came up with the following code but get the error Uncaught ReferenceError: printLine is not defined which makes sense but I don't really know where to go from here.
So.....Basically what I'm asking is, what's a good way to build up a chained function call without it actually being executed as javascript until I trigger it?
var buildLine = Function("input", "printLine('input')");
var lineItems = ['hello', 'world'];
var printPayload = '';
_.map(lineItems, function(item) {
printPayload += buildLine(item)
})
console.log(printPayload);
<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/3.10.1/lodash.min.js"></script>
.whatever().whatever().print(); some are much larger security holes than others, if you're including user-provided values, or values from outside libraries (or even including things, just on the page, like banner ads); do you have an exact, concrete example of what you want to provide, how you want to chain it, and what you want it to print, based on the input and instructions?