当前位置: 动力学知识库 > 问答 > 编程问答 >

javascript - ECMAscript 6 code not working

问题描述:

I'm new here.

I'm reading a book called ' Learning Javascript , 3rd edition ' and one of the exercises was running this code: :

"use strict";

let sentences = [

{ subject: 'JavaScript', verb: 'is', object: 'great' },

{ subject: 'Elephants', verb: 'are', object: 'large' },

];

function say( {subject, verb, object} ) {

console.log(`${subject} ${verb} ${object}`);

}

for(let s of sentences) {

say(s);

}

But this error appears.

SyntaxError : Unexpected token {

what is wrong with the code?

I'm using node.js, gulp.js and babel to transpiling for a es5 code.

P.S: Sorry for my bad english, i'm still learning and i'm trying not use the Google Tranlate

网友答案:

I found the solution

My gulp file was wrong, and I install the preset of 2015.

It is my gulp file now

var gulp = require('gulp');
var babel = require('gulp-babel');


gulp.task('default', () => {
return gulp.src("es6/**/*.js")
.pipe(babel({presets:["es2015"]}))
.pipe(gulp.dest("dist"));
});

Thanks for the peoples who helped me

分享给朋友:
您可能感兴趣的文章:
随机阅读: