There is a newbie to JavaScript here. I have the following code:
function testObject(elem) {
this.test = "hi";
this.val = elem;
console.log(this.test+this.val);
echo();
function echo () {
console.log(this.test+this.val);
}
}
var obj = new testObject("hello");
When it starts, I expect hihello to be displayed twice in the console. Instead, it displays as expected for the first time, but returns NaN a second time.
I'm sure something is missing here. I thought that an internal function could access the curtains outside. Can someone guide me? I am more a functional user interface developer and do not have much experience with OO code.
Thank!
source
share