[ES6] Use ES6 Proxies

Source: Internet
Author: User

A JavaScript Proxy allows-intercept operations performed on objects, arrays, or functions like property lookup, the Ignment, invocation, property deletion, and more to add custom behavior. In this lesson we looks at what intercept property lookup with get the "trap", that'll allow us to get items starting From the end of the array with ease.

console.clear ()ConstCharacters = [  'Harry Potter',  'Ron weasly',  'Hermione Granger',  'Nevel Longbottom',  'Lavender Brown',  'Scabbers',  'Pigwidgeon',]ConstHandler = {  //target:the Array itself//name:the Index which passed in Get(target, name) {//Check whether index is 0,1...6   if(Nameinchtarget) {          //If yes, then get the value back     returnReflect.Get(target, name)}Else {        //if not, then the name Is-1,-2, -3 ...     Constindex =Number (name); returnReflect.Get(Target, Target.length +index)} }}ConstProxy =NewProxy (characters, Handler) Console.log (proxy[3]);//Nevel LongbottomConsole.log (proxy[0]);//Harry PotterConsole.log (proxy[-2]);//Scabbers

[ES6] Use ES6 Proxies

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.