我正在尝试将用户对象绑定为 this 并将默认时间绑定为使用function.call方法的第一个参数
let user = {
name:'rifat',
txt (time, msg){
console.log('['+time+ '] '+ this.name+ ' : '+ msg);
}
}
function bind(func, ...fArgs){
return function(...args){
return func.call(this, ...fArgs, ...args);
};
}
let txt = bind(user.txt, new Date().getHours()+':' +new Date().getMinutes() );
txt('hey!');
为什么此代码返回未定义的名称。在节点 10.16.0.0 中运行
[18:21] undefined : hey!
慕桂英3389331
拉风的咖菲猫
相关分类