hasOwnProperty 很长,使我的代码无法通过长链式 if 语句读取。
有没有办法将 hasOwnProperty 重命名为“hop”、“has”或只是“h”,这样我就可以说类似的话
if(req.body.h('first_name') && req.body.h('last_name'))
{
//....
}
最佳答案
您可以引用原始的 hasOwnProperty方法。
Object.prototype.h = Object.prototype.hasOwnProperty;
const data = {a:1};
if(data.h('a')){
console.log('success');
}else{
console.log('false');
}
关于javascript - 如何重命名javascript对象函数hasOwnProperty?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55472583/