[英]JavaScript object.hasOwnProperty(proName) vs lodash _.has(obj, proName) function
I'm debating between using JavaScript Object.hasOwnProperty(propName)
and lodash _.has(obj, proName)
function to determine if an object has a property. 我正在讨论使用JavaScript
Object.hasOwnProperty(propName)
和lodash _.has(obj, proName)
函数来确定对象是否具有属性。
Which is more efficient for simple cases? 对于简单的案例,哪个更有效? For complex cases?
对于复杂的情况? For all cases?
对于所有情况?
Is there a better library that I haven't mentioned? 有没有更好的图书馆,我没有提到过?
Thanks! 谢谢!
Well the Lodash _.has()
method is just a call to Object.prototype.hasOwnProperty()
after a check for a null argument. 那么Lodash
_.has()
方法只是在检查null参数后调用Object.prototype.hasOwnProperty()
。 The code grabs a reference early on: 该代码早期抓住了一个参考:
var hasOwnProperty = Object.prototype.hasOwnProperty;
and then _.has(object, prop)
looks like 然后
_.has(object, prop)
看起来像
return object != null && hasOwnProperty.call(object, prop);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.