If I understand correctly, each and every object in JavaScript inherits from the Object prototype, which means that each and every object in JavaScript has access to the hasOwnProperty function through its prototype chain.
While reading RequireJS' source code, I stumbled upon this function:
function hasProp(obj, prop) {
return hasOwn.call(obj, prop);
}
hasOwn is a reference to Object.prototype.hasOwnProperty. Is there any practical difference to writing this function as
function hasProp(obj, prop) {
return obj.hasOwnProperty(prop);
}
And since we are at it, why do we define this function at all? Is it just a question of shortcuts and local caching of property access for (slight) performance gains, or am I missing any cases where hasOwnProperty might be used on objects which don't have this method?