Object.hasOwn() is intended as a replacement for Object.hasOwnProperty(). Object.hasOwn() 是作为 Object.hasOwnProperty() 的替代

    1. interface Object {
    2. /**
    3. * Determines whether an object has a property with the specified name.
    4. * @param o An object.
    5. * @param v A property name.
    6. */
    7. hasOwn(o: object, v: PropertyKey): boolean;
    8. }
    9. {
    10. // Object.hasOwn() is intended as a replacement for Object.hasOwnProperty().
    11. // Object.hasOwn() 是作为 Object.hasOwnProperty() 的替代
    12. const object = {
    13. name: 'dd'
    14. }
    15. let hasOwnProperty = Object.prototype.hasOwnProperty
    16. console.log(hasOwnProperty.call(object, 'name')) // true
    17. console.log(Object.hasOwn(object, 'name')) // true
    18. console.log(Object.hasOwn(object, 'age')) // false
    19. }