是否可以调用x.Enter,它会使用不同的参数第二次自动执行? [关闭]

问题描述 投票:0回答:1

问题是如何使用不同的参数再次执行该函数。

// my class
        let x = new class CB {

            constructor() {
                this.onEnter = function(callback) {
                    this.user = { user: 'Peter', isMember: true };
                    callback(this.user);
                }
            }
        }


//my call    

        x.onEnter(function(user) {
            console.log(user.user + " listed!");
        });

// How to do a second call....how with different parameters every time?
        console.log(x.onEnter);
    ...
javascript function callback
1个回答
1
投票

与您第一次使用相同的方法。您只需传递其他功能即可。

    x.onEnter(function(user) {
        console.log(user.user + " listed!");
    });
    x.onEnter(function(user) {
        console.log(user.user + " twisted!");
    });
© www.soinside.com 2019 - 2024. All rights reserved.