I have below two functions in two seperate files:
//homeFunction.js
import secondaryFunc from "./secondaryFunction.js";
const secFunc = new secondaryFunc(3);
secFunc.sayHello(5);
The another file is secondaryFunction.js:
function secondaryFunc(val){
this.val = val;
}
secondaryFunc.prototype.sayHello = (val1)=>{
console.log(this);
console.log("Hello");
}
export default secondaryFunc;
Here, when I execute homeFunction
, this
is undefined inside sayHello
function, which I don't understand because I have already created a reference to the secondaryFunc
, which has sayHello
as a property, so this
should not be undefined inside sayHello
. Please help me to understand this anomaly.
Thanks!