3 ms·
So basically a library tries to print something in the console and instead of using `console.log(...)` they use `print (...)` as if it is Python. That instead i
by a1371 7y ago
So basically a library tries to print something in the console and instead of using `console.log(...)` they use `print (...)` as if it is Python. That instead invokes `window.print` used to actually send something to the printer.
- camjohnson26 7y agoThis happens because of scope chaining in JavaScript. If you call a function it will look for it in the current context. If it’s not there it will try to find it in the parent. If it’s not there it will keep checking the parent objects until it finds it, or throw an exception. Since window is the top level context and includes a print function, it gets called and shows the printer dialog.
- minitech 7y agoNot the parent objects – the containing scopes. (Which is how scope works in most languages.)
- Arnavion 7y ago>instead of using `console.log(...)` they use `print (...)` as if it is Python. There's a `Module.print` that wraps `console.log` with a bit of logic. The code might have intended to call that one. window.Module = function (e, n, f) { var d = { }, p = [ 'DEBUGGING ENABLED' ]; return d.print = function (e) { return p.indexOf(e) < 0 && console.log('WASM: ' + e) }, d.printErr = function (e) { return console.error('WASM: ' + e) }, ... d }(e, n, f)