Learn Before
Concept

Object prototype properties

Avoid calling Object.prototype methods, especially those that are not meant to be polymorphic. These methods may be defined differently in other objects descending from Object.prototype. Use modern JavaScript utilities such as valueOf() and toString() only if polymorphic, and replace deprecated methods like defineGetter() with Object.defineProperty(). Replace propertyIsEnumerable()propertyIsEnumerable() with Object.getOwnPropertyDescriptor() and isPrototypeOf() with instanceof. If a semantically equivalent static method doesn't exist, call Object.prototype methods directly.

const obj = { foo: 1, // You should not define such a method on your own object, // but you may not be able to prevent it from happening if // you are receiving the object from external input propertyIsEnumerable() { return false; } } obj.propertyIsEnumerable("foo"); // false; unexpected result Object.prototype.propertyIsEnumerable.call(obj, "foo"); // true; expected result

0

1

Updated 2023-02-03

Contributors are:

Who are from:

Tags

Object-Oriented Programming (OOP) Languages

Related