简体   繁体   English

纯JavaScript中的ES6

[英]ES6 in plain javaScript

I would like to transform this snippet to plain javaScript: 我想将此代码段转换为简单的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... 我想我必须改变第一行...

You need to change the function definition and not use let . 您需要更改函数定义,而不要使用let There is no sign of a this in your code snippet, but note that this differs between => and function . 没有任何的迹象this在您的代码段,但请注意, this不同于之间=>function

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

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

}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM