Answer would be Option 3 -- Error
because Class
in JavaScript is (mostly) just syntactical sugar. The underlying working is same as the constructor function. Since, in the code snippet we are creating an instance, using the new
operator, but returning a non-primitive value from the constructor so implicit this
will be lost and instance won't have any getData
method to call.
To understand how new
operator works, watch https://www.youtube.com/watch?v=1FkZwBpti0o. The behaviour and concepts explained in the video applies to ES6 Classes also.