matthisk / es6console

🔮 Play with ECMAScript compilers
https://es6console.com
MIT License
152 stars 25 forks source link

Support plain ES6 without transpile #14

Open suntong opened 6 years ago

suntong commented 6 years ago

The current option of COMPILER are:

Please provide an option of no transpile (or JavaScript) so that people can try out plain ES6 as-is without transpile. Thx.

suntong commented 6 years ago

I'm new to JavaScript/ES6, so I need to know the exact behavior of JavaScript/ES6, not babel -- the following code behaves differently when run directly under JavaScript/ES6, or after babel transpile:

var obj1 = {a: 1, b: 2}; 
var obj3 = Object.assign({},obj1, obj2);
var obj2 = {a: 4, c: 110}; 
console.log(obj3);
obj3 = Object.assign({},obj1, obj2);
console.log(obj3);
suntong commented 6 years ago

Found another one,

https://es6console.com/jdxg96oh/

String.prototype.interpolate = function(params) {
  const names = Object.keys(params);
  const vals = Object.values(params);
  return new Function(...names, `return \`${this}\`;`)(...vals);
}

const template = 'Example text: ${text}';
const result = template.interpolate({
  text: 'Foo Boo'
});
console.log(result);

it's just plain normal ES6, but can't run in es6console.com.