Skip to content

Instantly share code, notes, and snippets.

@YarivGilad
Last active September 13, 2015 13:05
Show Gist options
  • Save YarivGilad/3fe267676b4e3d382d38 to your computer and use it in GitHub Desktop.
Save YarivGilad/3fe267676b4e3d382d38 to your computer and use it in GitHub Desktop.
Testing Node.js v4.0.0 modular ES6 syntax
//------------
// app.js
//------------
"use strict";
//import fs from 'fs'; // <-- Throws: SyntaxError: Unexpected reserved word ^^^^import
//import Project from './lib/Project'; // <-- Throws: SyntaxError: Unexpected reserved word ^^^^import
var Project = require('./lib/Project') //<-- works fine
var project = new Project("Journal");
console.log(project.start()); // --> logs "Project Journal starting"
//-----------------------
// ./lib/Project.js
//------------------------
"use strict";
class Project {
constructor(name) {
this.name = name;
}
start() {
return "Project " + this.name + " starting";
}
}
//export default Project; // <-- Does not work, throws: SyntaxError: Unexpected reserved word ^^^^export
module.exports = Project; // <-- Works fine
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment