Search code examples
javascriptperformancewindowtypeofhasownproperty

Why performance.hasOwnProperty('getEntries') returns false while typeof performance.getEntries returns function?


Window property performance has a function call getEntries to retrieve all performance entries. which works on all modern browsers but doesn't work on a few older browsers like Safari 10. To add a check of working browsers....

If we try to verify using performance.hasOwnProperty('getEntries'), It always return false. But it works if use typeof performance.getEntries === 'function'.

Would like to understand the logic behind it.


Solution

  • performance does not has own property “getEntries”, this property is owned by prototype of Performance, which is the constructor of performance object.

    when you use performance.getEntries(), actually Performance.prototype.getEntries() is called.