Skip to content Skip to sidebar Skip to footer

Is 'slot' A Reserve Word In Newer Version Of Ecmascript?

It's an issue with google chrome version 53.0.2785.101 (64-bit). I tried running a simple html file and it throws the error 'slot.testFun is not a function' when I used the word 's

Solution 1:

This isn't an ECMAScript issue, it is a DOM issue.

The slot attribute has a corresponding slot property, and onclick attributes do stupid things with with so you are effectively calling this.slot.testFun() because it finds slot (which defaults to being an empty string) before it gets to the right scope.

slot is a new addition to the DOM and support for slot is new in Chrome 53. It does not appear in Chrome 52 and might not have made it even into the latest version of other browsers.

The solution: Avoid intrinsic event attributes. Bind event handlers with DOM instead. That protects you from his clash and future-proofs you from future additions to the DOM.

<ahref="#">Click Here</a><scripttype="text/javascript">var slot = {
        testFun: function(){
            console.log('clicked');
        }
    }
    document.querySelector("a").addEventListener("click", slot.testFun);
</script>

Post a Comment for "Is 'slot' A Reserve Word In Newer Version Of Ecmascript?"