【发布时间】:2021-01-03 14:49:15
【问题描述】:
userSchema.virtual("password")
.set(function(password) {
//temp var
this._password = password;
//gen salt
this.salt = this.makeSalt();
//encrypt pass
this.hashed_password = this.encryptPassword(password);
})
.get(function () {
return this._password;
});
我想知道上面代码中“this”所指的范围。我有一个名为 userSchema 的 mongo 模式,我正在为其设置一个虚拟字段,即密码。只是好奇 this 在这里指的是什么通常在函数调用中 this 指的是全局范围。
【问题讨论】:
标签: javascript node.js reactjs mongodb mongoose