Reflect
is a global object in ES6 and later that provides the reflection API for JavaScript. Most strongly typed languages, such as Java, provide a reflection API which you can use to inspect and fine-tune the low-level structure of objects. Since JavaScript is a dynamic language, most of that functionality is already present in the language. However, Reflect
provides a more meaningful place for these functionalities.
Reflect
is not a function, so it is not callable (and it cannot be used with the new
operator). It is just a global object and all its methods are static methods.
The methods of Reflect
are the same methods that are available for ES6 proxies. However, proxies are not the subject of discussion in this post.
Here is a list of methods available from Reflect
global object:
defineProperty
getOwnPropertyDescriptor
getPrototypeOf
setPrototypeOf
preventExtensions
isExtensible
construct
apply
deleteProperty
has
ownKeys
get
set
Some of these methods are similar to the methods available on Object
and have similar functions, albeit sometimes a little different. For example, Reflect.defineProperty
has the same functionality as Object.defineProperty
, except that it returns a boolean indicating whether or not the operation was successful, whereas Object.defineProperty
returns the first argument as its return value.
Reflect.getOwnPropertyDescriptor
works in the same way as Object.getOwnPropertyDescriptor
.
Similarly, Reflect.getPrototypeOf
works in the same way as Object.getPrototypeOf
. However, for setPrototypeOf
, the return value is different. Object.setPrototypeOf
returns the given object, while Reflect.setPrototypeOf
returns a boolean value indicating whether or not the operation was successful.
Reflect.preventExtensions
works like Object.preventExtensions
, except that if the given argument is not an object, it throws a TypeError
. In the case of Object
, the argument is coerced to an object. The same situation exists with isExtensible
.
The rest of the methods will be discussed in future posts.
Related Posts
- JavaScript Basics: Object.create
- JavaScript Basics: Object.assign
- JavaScript Basics: Object.getPrototypeOf and Object.setPrototypeOf
- JavaScript Basics: Object.keys, Object.values, and Object.entries
- JavaScript Basics: Object.is
- JavaScript Basics: Object.prototype.hasOwnProperty
- JavaScript Basics: Object.preventExtensions and Object.isExtensible
- JavaScript Basics: Object.seal and Object.isSealed
- JavaScript Basics: Object.freeze and Object.isFrozen
script>
var ghasemakiani ="Its really helpful post and
very powerful language will
be in 2018";
alert('ghasemakiani');
</script
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
That's great gaming post. .Thanks for sharing ..
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Thank you sir.I have a question.Before you have post 2/3 each day(idioms tutorial)
But now you have post so low number.
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Thank you @sharifulislamm. I am experimenting with new types of posts. I may have some other language-related posts in the future. Thank you for your interest and support.
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Feeling happy that it begins again. Resteem done :D
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
This is very helpful to learn java .Java is one of the most useful program.thank you
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Nice post.
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
oh , thanks so much for sharing this info
.. so.. is it true that we can not create a new object from them cause they are static? and... is it true if i say reflect is as like as property ?
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Yes. Reflect is a global object like Math.
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
nice post bro
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Mamnunam az lotfetun aghaye ghasemkiani :) 🙏
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Sepaas
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
nice to see your blog about programming again.
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
thanks, i'm used to old plain javascript, but this is something else, will definitely help me with my coding, thanks for the post
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
nice post.java is a good language.
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Hello friend, this contribution of JavaScript is very good for our learning thanks for sharing.
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
javascript is awsome language,carry on
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Good job man......great working......great thinking...creative mind...keep it up!!!......
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Resteemit done..
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Great post dear..I appreciate your post...Keep it up..
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Very nice post...
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Thanks for this programming sharing...... i appreciate this post. best of luck...
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Great job.Dear!!!!!
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
fabulous one
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
i like this programming and good post about java script.... i just want to say that its good
....
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
As a follower of @followforupvotes this post has been randomly selected and upvoted! Enjoy your upvote and have a great day!
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
upvote and resteemit done dear....
keep it on....
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Very useful post.
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
love to read it .........
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Great! great work
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Good Post.
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Thanks for sharing about javascript
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
another good lesson in javascript, thanks for the post, really learning some nice javascript coding from you.
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
thank you for all your good post on the javascript, Reflect really helps
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
thnkas for sharing it .java script is awsome
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Need your support sir. Please.
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit