NEWBIE question.
I cannot access member function. What am I doing wrong?
index.js ->
var abc = require('./def');
var foo = new abc();
foo.zxc();
def.js ->
var bar = function(){
// do something
var zxc = function(){
// do something
}
}
module.exports = def;
When I run in brwoser console it shows :
TypeError:foo.zxc is not a function
Because zxc is just a local variable not accessible from outside of the the bar function. You can change it to
var bar = function() {
// do something
this.zxc = function(){
// do something
}
}
Now, zxc is an own property of the constructed object so it will work.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With