Reputation: 9830
I'm trying to return an object with a function inside. When I call it, I get an error:
Uncaught TypeError: config.something is not a function
What am I doing wrong, and how can I fix it?
function config() {
function something() {
console.log('something');
}
return {
something: something
};
}
config.something();
Upvotes: 0
Views: 100
Reputation: 18753
Since config
is a function not an object you need to call/execute it, this then returns the object that you can call .something
on.
function config() {
function something() {
console.log('something');
}
return {
something: something
};
}
config().something();
var config = {
something: function() {
console.log('something');
}
};
config.something();
More resources:
Upvotes: 3