user3142695
user3142695

Reputation: 17332

ES6 in plain javaScript

I would like to transform this snippet to plain javaScript:

Meteor.startup(() => {
    if (!Meteor.users.findOne({name: 'anything'})) {
        let id = Accounts.createUser({
            username: 'admin',
            email: 'admin',
            password: 'admin'
        });
    }
});

I think I have to transform the first line...

Upvotes: 0

Views: 269

Answers (2)

Remya CV
Remya CV

Reputation: 144

you could change it up a little bit like:

 Meteor.startup(function() {
if (Meteor.users.find().count() == 0){
       Accounts.createUser({
        username: 'admin',
        email: 'admin',
        password: 'admin'
       });
    }

}

Upvotes: 0

Simon H
Simon H

Reputation: 21005

You need to change the function definition and not use let. There is no sign of a this in your code snippet, but note that this differs between => and function.

Meteor.startup(function() {
    if (!Meteor.users.findOne({name: 'anything'})) {
        var id = Accounts.createUser({
            username: 'admin',
            email: 'admin',
            password: 'admin'
        });
    }
});

Upvotes: 5

Related Questions