0

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...

4
  • The first line is anonymous function Commented Sep 9, 2015 at 7:51
  • I think he means arrow function... developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/… a function with no arguments requires parentheses. Commented Sep 9, 2015 at 7:57
  • 1
    For future ES6 => ES5 needs, I recommend babeljs.io/repl Commented Sep 9, 2015 at 9:10
  • There is this tool for automatically converting ES6 into plain JavaScript: /bin/cat. Commented Nov 17, 2024 at 11:17

2 Answers 2

5

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'
        });
    }
});
Sign up to request clarification or add additional context in comments.

Comments

0

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'
       });
    }

}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.