Jump to content
RAGE Multiplayer Community

es6 classes


tortilla
 Share

Recommended Posts

So, I've created simple class called Event inside my resources and I've made new instance of this class inside server-side entrypoint. After executing server.exe I have a lot of errors inside console.

Source code:

//Event.js
export class Event {
    constructor(name, callback) {
        this.name = name;
        this.callback = callback;
    }
}

//index.js
const Event = require( './modules/event/Event.js');

const testEvent = new Event("test", function() {});
console.log(testEvent);

Errors:

Error: E:\gry\RAGEMP\lsonline\server-files\packages\LSOnline\modules\event\Event.js:3
export class Event {
^^^^^^

SyntaxError: Unexpected token export
    at createScript (vm.js:80:10)
    at Object.runInThisContext (vm.js:152:10)
    at Module._compile (module.js:605:28)
    at Object.Module._extensions..js (module.js:652:10)
    at Module.load (module.js:560:32)
    at tryModuleLoad (module.js:503:12)
    at Function.Module._load (module.js:495:3)
    at Module.require (module.js:585:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (E:\gry\RAGEMP\lsonline\server-files\packages\LSOnline\index.js:6:15)

 

I've tried to use import instead of require but it didn't help me. Can somebody write me something small and simple tutorial how to implement class? Maybe I've made some simple mistake and I can't find it. Thanks for helping me.

Link to comment
Share on other sites

  • 2 weeks later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...