A quick, dirty, and evil template for compiling ES6 in the browser.
The Function constructor is a form of eval, and using it is a bad practice.
Also, using Babel in the browser is slow and deprecated.
So, never do this. 😁
| license: gpl-3.0 |
A quick, dirty, and evil template for compiling ES6 in the browser.
The Function constructor is a form of eval, and using it is a bad practice.
Also, using Babel in the browser is slow and deprecated.
So, never do this. 😁
| <!DOCTYPE html> | |
| <head> | |
| <meta charset="utf-8"> | |
| <script src="https://d3js.org/d3.v4.min.js"></script> | |
| <script src="https://cdnjs.cloudflare.com/ajax/libs/babel-standalone/6.10.3/babel.min.js"></script> | |
| <style> | |
| body { margin:0;position:fixed;top:0;right:0;bottom:0;left:0; } | |
| </style> | |
| </head> | |
| <body> | |
| <script> | |
| d3.text('script.js', function(err, source) { | |
| var options = { presets: ['es2015'] }; | |
| var compiled = Babel.transform(source, options).code; | |
| (new Function(compiled))(); | |
| }) | |
| </script> | |
| </body> |
| const [ a, b ] = [ 'code', 'below' ]; | |
| const { c } = { c: 'change' }; | |
| const baz = ({ a, b, c }) => `Edit the ${a} ${b} to ${c} me!`; | |
| const svg = d3.select("body").append("svg") | |
| .attr("width", 960) | |
| .attr("height", 500); | |
| svg.append("text") | |
| .text(baz({ a, b, c })) | |
| .attr("y", 200) | |
| .attr("x", 120) | |
| .style("font-size", 36) | |
| .style("font-family", "monospace"); |