Quantcast
Channel: User Brett Merrifield - Stack Overflow
Viewing all articles
Browse latest Browse all 37

Answer by Brett Merrifield for 'is not a function' on calling an method within the same constructor function (JS)

$
0
0

When you use function() { ... } it changes what this is while inside the function. You either need to bind the function to this or use an arrow function () => { ... }.

Using bind:

var handleClick = function() {    this.close();};this.dialog.onclick = handleClick.bind(this)

Using arrow function:

this.dialog.onclick = () => {    this.close();}

Viewing all articles
Browse latest Browse all 37


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>