var model = {
test:function(){console.log("hello")},
show: test() //ReferenceError: test is not defined
}
I want to have a key inside model object to hold a function. Not sure why it gets undefined error.
var model = {
test:function(){console.log("hello")},
show: test() //ReferenceError: test is not defined
}
I want to have a key inside model object to hold a function. Not sure why it gets undefined error.
I know this is a duplicate but I can't find a good one. You have to do something like this:
var model = {
test:function(){console.log("hello")},
};
model.show = model.test();
If you want to make it less ... primitive, I guess, you can write a constructor function to encapsulate that stuff, or perhaps a "factory"-like function to do so.