Help us understand the problem. What is going on with this article?

ES6の構文にブラウザが対応しているかチェックするスニペット。

More than 3 years have passed since last update.

開発者ツールのコンソールなどに流し込んで使う

try {
    eval('(function() { yield 1 })()');
    console.log('%c%s', 'color:green', 'yield を使えます');
} 
catch (e) { console.log('%c%s', 'color:red', 'yield は使えません') }


try {
    eval('(function(a=10) { return a })()');
    console.log('%c%s', 'color:green', 'デフォルト引数 を使えます');
} 
catch (e) { console.log('%c%s', 'color:red', 'デフォルト引数 は使えません') }

try {
    eval('(function(...numbers) { return numbeers })()');
    console.log('%c%s', 'color:green', '可変引数 を使えます');
} 
catch (e) { console.log('%c%s', 'color:red', '可変引数 は使えません') }

try {
    eval('(()=>{ return null })();');
    console.log('%c%s', 'color:green', 'アローファンクション を使えます');
} 
catch (e) { console.log('%c%s', 'color:red', 'アローファンクション は使えません') }

try {
    eval('(function() { let foo = 1 })()');
    console.log('%c%s', 'color:green', 'let を使えます');
} 
catch (e) { console.log('%c%s', 'color:red', 'let は使えません') }

try {
    eval('(function*() { const foo = 1 })()');
    console.log('%c%s', 'color:green', 'const を使えます');
} 
catch (e) { console.log('%c%s', 'color:red', 'const は使えません') }

try {
    eval('(function() { var myMap = new Map(); })()');
    console.log('%c%s', 'color:green', 'Map を使えます');
} 
catch (e) { console.log('%c%s', 'color:red', 'Map は使えません') }

実行例(Chrome)

kyoju000004.JPG

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした