11/11/2022 0 Comments Reflection examples![]() ![]() Reflect.getPrototypeOf() – is the same as Object.getPrototypeOf().It returns a property descriptor of a property if the property exists on the object, or undefined otherwise. Reflect.getOwnPropertyDescriptor() – is similar to Object.getOwnPropertyDescriptor().Reflect.get() – return the value of a property.It’s equivalent to calling the delete objectName. leteProperty() – behave like the delete operator, but as a function.fineProperty() – is similar to fineProperty(), but return a Boolean value indicating whether or not the property was successfully defined on the object.It is equivalent to calling new target(.args). ![]() nstruct() – act like the new operator, but as a function.Reflect.apply() – call a function with specified arguments.All the methods of the Reflect object are static. It is similar to the Math and JSON objects. It means that you cannot use Reflect with the new operator or invoke the Reflect as a function. ![]() Unlike the most global objects, the Reflect is not a constructor. The Reflect API is important because it allows you to develop programs and frameworks that are able to handle dynamic code. For example, methods like Object.keys(), Object.getOwnPropertyDescriptor(), and Array.isArray() are the classic reflection features.ĮS6 introduces a new global object called Reflect that allows you to call methods, construct objects, get and set properties, manipulate and extend properties. Prior to ES6, JavaScript already has reflection features even though they were not officially called that by the community or the specification. In computer programming, reflection is the ability of a program to manipulate variables, properties, and methods of objects at runtime. Summary: in this tutorial, you will learn about the JavaScript reflection and Reflect API in ES6. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |