{"id":2235,"date":"2015-09-29T06:11:26","date_gmt":"2015-09-29T06:11:26","guid":{"rendered":"http:\/\/www.nikola-breznjak.com\/blog\/?p=2235"},"modified":"2015-09-29T06:14:23","modified_gmt":"2015-09-29T06:14:23","slug":"how-to-use-ecmascript-6-features-in-ionic-framework","status":"publish","type":"post","link":"https:\/\/nikola-breznjak.com\/blog\/stack-overflow\/how-to-use-ecmascript-6-features-in-ionic-framework\/","title":{"rendered":"How to use ECMAScript 6 features in Ionic framework?"},"content":{"rendered":"<p><a href=\"http:\/\/stackoverflow.com\/users\/534755\/nikola\"><img loading=\"lazy\" decoding=\"async\" title=\"profile for Nikola at Stack Overflow, Q&amp;A for professional and enthusiast programmers\" src=\"http:\/\/stackoverflow.com\/users\/flair\/534755.png\" rel=\"lightbox[2235]\" alt=\"profile for Nikola at Stack Overflow, Q&amp;A for professional and enthusiast programmers\" width=\"208\" height=\"58\" \/><\/a><br \/>\nI&#8217;m a big fan of <a href=\"http:\/\/stackoverflow.com\/\">Stack Overflow<\/a> and I tend to contribute regularly (am currently in the <a href=\"http:\/\/stackexchange.com\/leagues\/1\/alltime\/stackoverflow\/2008-07-31\/534755?sort=reputationchange#534755\">top 0.X%<\/a>).\u00a0In this category (<a href=\"http:\/\/www.nikola-breznjak.com\/blog\/category\/stack-overflow\/\">stackoverflow<\/a>)\u00a0of posts, I will be posting my top rated questions and answers. This, btw, is allowed as explained in the meta thread <a href=\"http:\/\/meta.stackoverflow.com\/questions\/266971\/can-i-post-so-questions-and-answers-in-a-personal-blog\/266973\">here<\/a>.<\/p>\n<p>As you may know, I&#8217;m really into Ionic framework lately\u00a0and am helping out on StackOverflow with the knowledge I gained so far with the framework. I&#8217;m in the top 5 All time answerers.<\/p>\n<p>I answered\u00a0<a href=\"http:\/\/stackoverflow.com\/questions\/32784376\/how-to-use-ecmasscript-6-features-in-ionic\/32798045\">this question<\/a>\u00a0by user <a href=\"http:\/\/stackoverflow.com\/users\/5148540\/user5148540\">user5148540<\/a>:<\/p>\n<p>I recently used the new Set data structure specification instead of an array where I didn&#8217;t wanted any repeated values to be stored and it is working without problems, but I&#8217;m wondering I want to implement some of the new features such as <code>let<\/code>, <code>class<\/code> and <code>const<\/code>.<\/p>\n<p>I&#8217;m using also the crosswalk plugin in case this is relevant.<\/p>\n<p>Can anyone tell me if I should avoid ES6 for the moment or if its okay to be used?<\/p>\n<p>My <a href=\"http:\/\/stackoverflow.com\/questions\/32784376\/how-to-use-ecmasscript-6-features-in-ionic\/32798045#32798045\">answer<\/a> was:<\/p>\n<blockquote><p>I actually googled about this myself earlier today and I found this tutorial:<a href=\"http:\/\/labs.encoded.io\/2015\/06\/22\/use-es6-with-ionic\/\" rel=\"nofollow\">http:\/\/labs.encoded.io\/2015\/06\/22\/use-es6-with-ionic\/<\/a><\/p>\n<p><em>StackOverflow encourages to not just use links as answers, so I&#8217;m just going to give my TL;DR, since this is not my own site and I don&#8217;t want to be held accountable for c\/p.<\/em><\/p>\n<p>Ionic uses Gulp, so install gulp-babel and gulp-plumber.<\/p>\n<pre class=\"lang:default decode:true\">npm install --save-dev gulp-babel gulp-plumber<\/pre>\n<p>Add babel to <code>gulpfile.js<\/code> like so:<\/p>\n<pre class=\"lang:default decode:true\">\/\/...\r\nvar babel = require(\"gulp-babel\");\r\nvar plumber = require(\"gulp-plumber\");\r\n\r\nvar paths = {\r\n  es6: ['.\/src\/es6\/*.js'],\r\n  sass: ['.\/scss\/**\/*.scss']\r\n};\r\n\r\ngulp.task('default', ['babel', 'sass']);\r\n\r\ngulp.task(\"babel\", function () {\r\n  return gulp.src(paths.es6)\r\n    .pipe(plumber())\r\n    .pipe(babel())\r\n    .pipe(gulp.dest(\"www\/js\"));\r\n});\r\n\r\n\/\/...\r\n\r\ngulp.task('watch', function() {\r\n  gulp.watch(paths.es6, ['babel']);\r\n  gulp.watch(paths.sass, ['sass']);\r\n});\r\n\/\/...<\/pre>\n<p>Edit <code>ionic.project<\/code>:<\/p>\n<pre class=\"lang:default decode:true\">\"gulpStartupTasks\": [\r\n    \"babel\",\r\n    \"sass\",\r\n    \"watch\"\r\n ],<\/pre>\n<p>For any more details consult the original link &#8211; and with this I also say thanks to the author of that blog post as it helped me too.<\/p><\/blockquote>\n<blockquote class=\"twitter-tweet\" data-width=\"550\">\n<p lang=\"en\" dir=\"ltr\">How to use <a href=\"https:\/\/twitter.com\/hashtag\/ECMAScript?src=hash\">#ECMAScript<\/a> 6 features in <a href=\"https:\/\/twitter.com\/hashtag\/Ionic?src=hash\">#Ionic<\/a> framework?<a href=\"http:\/\/t.co\/kyur9xI2Dy\">http:\/\/t.co\/kyur9xI2Dy<\/a> <a href=\"http:\/\/t.co\/e2JCzStBKF\">pic.twitter.com\/e2JCzStBKF<\/a><\/p>\n<p>&mdash; Nikola Bre\u017enjak (@HitmanHR) <a href=\"https:\/\/twitter.com\/HitmanHR\/status\/648742429940551684\">September 29, 2015<\/a><\/p><\/blockquote>\n<p><script async src=\"\/\/platform.twitter.com\/widgets.js\" charset=\"utf-8\"><\/script><\/p>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;m a big fan of Stack Overflow and I tend to contribute regularly (am currently in the top 0.X%).\u00a0In this category (stackoverflow)\u00a0of posts, I will be posting my&hellip;<\/p>\n","protected":false},"author":1,"featured_media":2236,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[43,35],"tags":[],"class_list":["post-2235","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-ionic","category-stack-overflow"],"_links":{"self":[{"href":"https:\/\/nikola-breznjak.com\/blog\/wp-json\/wp\/v2\/posts\/2235","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/nikola-breznjak.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/nikola-breznjak.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/nikola-breznjak.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/nikola-breznjak.com\/blog\/wp-json\/wp\/v2\/comments?post=2235"}],"version-history":[{"count":3,"href":"https:\/\/nikola-breznjak.com\/blog\/wp-json\/wp\/v2\/posts\/2235\/revisions"}],"predecessor-version":[{"id":2239,"href":"https:\/\/nikola-breznjak.com\/blog\/wp-json\/wp\/v2\/posts\/2235\/revisions\/2239"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/nikola-breznjak.com\/blog\/wp-json\/wp\/v2\/media\/2236"}],"wp:attachment":[{"href":"https:\/\/nikola-breznjak.com\/blog\/wp-json\/wp\/v2\/media?parent=2235"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/nikola-breznjak.com\/blog\/wp-json\/wp\/v2\/categories?post=2235"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/nikola-breznjak.com\/blog\/wp-json\/wp\/v2\/tags?post=2235"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}